mail()无法正常工作

时间:2012-08-21 23:11:55

标签: php email

我正在尝试在发送表单时发送电子邮件,但没有发生任何事情。我使用winHost作为提供者。我试过制作一个单独的.php文件来测试mail()函数,但没有雪茄 -     mail('myemail','dfd','dsaf','dasfda');

这是我的邮寄设置 -

    $to = $agentemail;
$subject = "";
$message = "";
$from = "";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);

如果您需要更多信息,请与我们联系。

1 个答案:

答案 0 :(得分:0)

正如@alfasin指出的那样,你需要按照他给WinHost Knowledge Base的第一个链接上的示例代码:

您需要将主机和用户名替换为您已设置的实际电子邮件帐户的详细信息。

<?php 
require_once "Mail.php"; 
$from = "Sender <postmaster@HostingAccountDomain.com>"; 
$to = "Recipient <user@HostingAccountDomain.com>"; 
$subject = "This is a test email sent via php"; 
$body = "This is a test email"; 

$host = "mail.HostingAccountDomain.com"; 
$username = "postmaster@HostingAccountDomain.com"; 
$password = "email_password"; 

$headers = array ('From' => $from, 
                  'To' => $to, 
                  'Subject' => $subject); 

$smtp = Mail::factory('smtp', 
                      array ('host' => $host, 
                             'auth' => true, 
                             'username' => $username, 
                             'password' => $password)
                      ); 
$mail = $smtp->send($to, $headers, $body); 
?>