1

这是我向新用户发送确认电子邮件的 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;

}

我没有错误

4

2 回答 2

0

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

于 2013-09-29T21:54:13.620 回答
0

安装phpmailer

这是一个关于如何使用 PHP 邮件程序发送邮件的示例

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;
    }
}
于 2013-09-29T21:39:23.457 回答