2014-09-04 55 views
2

我想使用Gmail SMTP服務器通過PHP梅勒我的網站,發送電子郵件,遺憾的是它不發送其不顯示任何像processForm.php ERRORINFO或消息已被髮送,下面是我的代碼可以在任何一個可以告訴我爲什麼它不工作通過PHP發送郵件程序使用Gmail的SMTP服務器從網站的電子郵件

processForm.php

<?php 

print "hi"; 



include "class.phpmailer.php"; // include the class file name 
$mail = new PHPMailer(); // create a new object 
$mail->IsSMTP(); // enable SMTP 
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only 
$mail->SMTPAuth = true; // authentication enabled 
$mail->SMTPSecure = 'ssl'; 
$mail->Host = "smtp.gmail.com"; 
$mail->Port = 465; // or 587 
$mail->IsHTML(true); 
$mail->Username = "[email protected]"; 
$mail->Password = "xxxxxx"; 
$mail->SetFrom("[email protected]"); 
$mail->Subject = "Test"; 
$mail->Body = "hello"; 
$mail->AddAddress("[email protected]"); 
if(!$mail->Send()) 
    { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
    } 
    else 
    { 
    echo "Message has been sent"; 
    } 

    ?> 

回答

-1

嘗試使用此

$mail->Host = "smtp.googlemail.com"; 

inste廣告

$mail->Host = "smtp.gmail.com"; 

另一種解決方案也在這裏。不使用class.phpmailer.php

$to = '[email protected]'; 

    $from = '[email protected]'; 
    $subject = 'Test';  
    $msg = 'hello'; 
    $headers = "From:". $from; 
    $message = "Hello"; 

    if(!mail($to,$subject,$message,$headers)) { 
     echo 'Error'; 
    } 
    else { 
     echo "Success"; 
    } 
+0

OP已經使用PHPMailer的 - 讓你的「答案」在這裏不添加任何新的東西,或任何涉及到企業的實際問題。請回答一個問題,只有當你有一個_actual_回答手頭的問題,但不只是爲了回答一些的緣故。 – CBroe 2014-09-04 13:13:59

+0

在我的情況,包括/只使用class.phpmailer.php不整的PHPMailer它不工作。所以我用這種方式,工作得很好。所以你不能投票給我。 @Xavi請嘗試這種方式,讓我知道它的工作與否。 – herr 2014-09-04 13:49:51

0
$mail->SMTPSecure = 'tls'; 

使用這種替代SSL它可能工作。

相關問題