我正在使用PHPMAILER,但是我还很新。
我使用了以下代码,但是由于某种原因,该电子邮件已被发送到垃圾邮件。请查看代码,并告诉我需要修复的内容。 (我是刚接触电子邮件的人
<?php
require 'php-mailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isMail(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'kfhcareer@gmail.com.com'; // SMTP username
$mail->Password = 'password12345'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('kfhcareer@gmail.com', 'KFH Bahrain');
$mail->addAddress('kfhcareer@gmail.com', 'Joe User'); // Add a recipient
$mail->AddReplyTo( 'mailer@blah.com', 'Contact BLah' );
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'KFH house bahrain';
$mail->Body = 'This is tthe message <b>in bold!</b>';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
答案 0 :(得分:-2)
require("PHPMailer/class.phpmailer.php");
$sender = "sender@gmail.com"; //gmail of the sender
$password = "senderpassword"; //the password
$receiver = "receiver@gmail.com"; // the receiver email
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPDebug = 2;
$mail->From = $sender;
$mail->FromName = $sender;
$mail->Host = "smtp.gmail.com"; // specif smtp server
$mail->SMTPSecure= "ssl"; // Used instead of TLS when only POP mail is selected
$mail->Port = 465; // Used instead of 587 when only POP mail is selected 465
$mail->SMTPAuth = true;
$mail->Username = $sender; // SMTP username
$mail->Password = $password; // SMTP password
$mail->AddAddress($receiver, $receiver); //replace myname and mypassword to yours
$mail->AddReplyTo($receiver, $receiver);
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "This is Subject";
$mail->Body = "This is Body";
if(!$mail->Send()){
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}