PHP没有收到电子邮件

时间:2013-09-29 19:04:19

标签: php

这是我的PHP代码,向新用户发送确认电子邮件,问题是,我没有收到它(我尝试了不同的,没有运气)

function send_email($info)
{


    //format each email
$body = format_email($info,'html');
$body_plain_txt = format_email($info,'txt');


    //setup the mailer
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance();
$message ->setSubject('Welcome to Site Name');
$message ->setFrom(array('noreply@localhost' => 'localhost'));
$message ->setTo(array($info['email'] => $info['username']));

$message ->setBody($body_plain_txt);
$message ->addPart($body, 'text/html');

$result = $mailer->send($message);

return $result;

}

我没有错误

2 个答案:

答案 0 :(得分:0)

安装phpmailer

以下是how to send mail with PHP mailer

上的示例
function smtpmailer($to, $from, $from_name, $subject, $body) { 
    global $error;
    $mail = new PHPMailer();  // create a new object
    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth = true;  // authentication enabled
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
    $mail->Host = 'smtp.gmail.com';
    $mail->Port = 465; 
    $mail->Username = GUSER;  
    $mail->Password = GPWD;           
    $mail->SetFrom($from, $from_name);
    $mail->Subject = $subject;
    $mail->Body = $body;
    $mail->AddAddress($to);
    if(!$mail->Send()) {
        $error = 'Mail error: '.$mail->ErrorInfo; 
        return false;
    } else {
        $error = 'Message sent!';
        return true;
    }
}

答案 1 :(得分:0)

如果您的目标地址为@hotmail.com,则可能永远不会收入,因为他们拥有强大的反垃圾邮件管理功能。