2013-09-29 95 views
1

這是我的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('[email protected]' => 'localhost')); 
$message ->setTo(array($info['email'] => $info['username'])); 

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

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

return $result; 

} 

我得到沒有錯誤

+0

你檢查了垃圾郵件嗎? – Headshota

+1

localhost?您使用的是哪個郵件服務器? – 2013-09-29 19:08:00

+0

你在乎你如何發送郵件,或者你只是想發送郵件? – TAAPSogeking

回答

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; 
    } 
} 
0

樣本如果你的目的地址是@hotmail.com它可能永遠不會收入,因爲他們擁有強大的反垃圾郵件管理。

相關問題