Php邮件程序无法通过webmail

时间:2016-03-20 16:35:26

标签: smtp phpmailer webmail

我没有在我的网络邮箱上收到任何邮件,但是如果我把gmail凭证我收到邮件

 $mail = new PHPMailer();  

// Set up SMTP  

$mail->IsSMTP();                // Sets up a SMTP connection  
$mail->SMTPAuth = true;         // Connection with the SMTP does require authorization    
$mail->SMTPSecure = "ssl";      // Connect using a TLS connection  
$mail->Host = "mail.gmail.com";  //Gmail SMTP server address
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                      // 1 = errors and messages
                                      // 2 = messages only
$mail->SMTPAuth   = true;  
$mail->Port = 465;  //Gmail SMTP port
$mail->Encoding = '7bit';

// Authentication  
$mail->Username   = "admin@example.com"; // Your full  address
$mail->Password   = "password"; // Your  password

// Compose
$mail->SetFrom($_POST['emailid'], $_POST['fullname']);
$mail->AddReplyTo($_POST['emailid'], $_POST['fullname']);
$mail->Subject = "New Contact Form Enquiry";      // Subject (which isn't required)  
$mail->MsgHTML($message);

// Send To  
$mail->AddAddress("recipientemail@gmail.com", "Recipient Name"); // Where to send it - Recipient
$result = $mail->Send();        // Send!  
$message = $result ? 'Successfully Sent!' : 'Sending Failed!';      
unset($mail);

我已经尝试了10次但是在gmail上接收邮件而不是在webmail上

1 个答案:

答案 0 :(得分:0)

您正在SMTPSecure = "ssl"使用Port = 587。这不会起作用,如果您不愿意将代码置于the gmail example provided with PHPMailer而不是在其他地方发现的一些破碎,过时的东西,那么您就会知道。

至少应将SMTPSecure = "tls"Port = 587一起使用,然后按reading the docs进行操作。