我正在尝试通过PHP邮件程序使用Gmail SMTP服务器从我的网站发送电子邮件,遗憾的是它没有发送任何类似于processForm.php的信息,错误信息或邮件已发送,下面是我的代码可以任何人告诉我为什么它不起作用
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 = "xxxxxxxxx6@gmail.com";
$mail->Password = "xxxxxx";
$mail->SetFrom("arokxavi16@gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("arokiaxavierraja16@gmail.com");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
答案 0 :(得分:0)
$mail->SMTPSecure = 'tls';
使用它而不是ssl它可能会起作用。
答案 1 :(得分:-1)
尝试使用此
$mail->Host = "smtp.googlemail.com";
而不是
$mail->Host = "smtp.gmail.com";
另一种解决方案也在这里。不使用class.phpmailer.php
$to = 'arokiaxavierraja16@gmail.com';
$from = 'xxxxxx@gmail.com';
$subject = 'Test';
$msg = 'hello';
$headers = "From:". $from;
$message = "Hello";
if(!mail($to,$subject,$message,$headers)) {
echo 'Error';
}
else {
echo "Success";
}