$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上
答案 0 :(得分:0)
您正在SMTPSecure = "ssl"
使用Port = 587
。这不会起作用,如果您不愿意将代码置于the gmail example provided with PHPMailer而不是在其他地方发现的一些破碎,过时的东西,那么您就会知道。
至少应将SMTPSecure = "tls"
与Port = 587
一起使用,然后按reading the docs进行操作。