使用SMTP和电子邮件从PHP发送电子邮件到垃圾邮件.将电子邮件发送到收件箱最简单的方法是什么? [英] Sending email from PHP using SMTP and email goes to spam.What will be easiest way to send email to inbox?
本文介绍了使用SMTP和电子邮件从PHP发送电子邮件到垃圾邮件.将电子邮件发送到收件箱最简单的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用SMTP从PHP发送电子邮件,但是每次我在垃圾邮件中接收电子邮件时.我在Google上搜索并获得了一些解决方案,但仍然收到垃圾邮件.您能帮我吗?
I am trying to send email from PHP using SMTP but every time I am getting emails in my spam. I searched on google and got some solution but still I am getting email in spam. Would you help me in this?
//$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'abc@gmail.com'; // SMTP username
$mail->Password = '***'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption,'ssl' also accepted
$mail->Port = 587; //Set the SMTP port number - 587 for authenticated TLS
$mail->setFrom('abc@gmail.com', 'admin'); //Set who the message is to be sent from
$mail->addReplyTo('abc@gmail.co', 'First Last'); //Set an alternative reply-to address
$mail->addAddress($to, 'user'); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Hello';
$mail->Body = "<html>
<head>
<title>HTML email</title>
</head>
<body>
<a href='/changepassword.php?user_id=" .$User_id1."'>Create your password here</a>
</body>
</html>";
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
推荐答案
// Use phpmailer library from github install and use
require_once('PHPMailer/PHPMailerAutoload.php');
if(isset($_REQUEST['submit']))
{
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = "Name : ".$_REQUEST['name']."<br> Email Id ".$_REQUEST['email']."<br> message ".$_REQUEST['message'];
$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "mail.xx.co";
$mail->Port = 25;
$mail->Username = "support@xx.co"; // SMTP username
$mail->Password = "xxxxxxxxxx"; // SMTP password
$mail->SetFrom('support@xx.co',$_REQUEST['subject']);
$mail->AddAddress('support@xx.co', $_REQUEST['name']);
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = $_REQUEST['subject'];
$mail->Body = $body;
if(!$mail->Send()) {
echo '<strong>Email</strong> sent failed.';
} else {
echo '
<strong>Email</strong> s`enter code here`ent successfully.';
}
}
// get smtp host detail from the cpanel
这篇关于使用SMTP和电子邮件从PHP发送电子邮件到垃圾邮件.将电子邮件发送到收件箱最简单的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文