使用PHP Mailer发送电子邮件
我正在尝试使用PHP Mailer发送电子邮件。该网站被上传到一个免费的主机上。显示有关SMTP连接失败的错误。我希望找一个在这件事上有专长的人 这是我的密码使用PHP Mailer发送电子邮件,php,phpmailer,Php,Phpmailer,我正在尝试使用PHP Mailer发送电子邮件。该网站被上传到一个免费的主机上。显示有关SMTP连接失败的错误。我希望找一个在这件事上有专长的人 这是我的密码 require '../extensions/phpmailer/PHPMailerAutoload.php'; $emailAddress = 'SampleEmail'; $password = 'Emailpassword'; $subject = '
require '../extensions/phpmailer/PHPMailerAutoload.php';
$emailAddress = 'SampleEmail';
$password = 'Emailpassword';
$subject = 'Invitation to employee portal';
$message = '
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Invitation</title>
<body style ="background:#eee;">
<table cellpadding="0" cellspacing="0" border="0" id="backgroundTable" style ="padding: 40px; max-width:640px;background-color:#f3f3f3;display:block;margin:0 auto; font-family:Lato, sans-serif; color:#626262;font-size:13px;line-height:22px;" width ="600">
<tbody>
<tr>
<td style ="background-color: #3552f2; padding: 34px 122px;">
<h1 width ="600" style ="max-width:600px;width:100%; text-align:center; color:#fff;">HRMS DHVTSU</h1>
</td>
</tr>
<tr>
<td style ="background-color: #ffffff; text-align: center; padding: 40px;">
<h1 style="font-size: 40px; color:#000; font-style: italic;">Sorry your account has been deactivated.</h1>
<br>
<p style ="color:#000; font-size: 16px;">For any questions please contact HR Department.</p>
<br>
<br>
</td>
</tr>
<tr>
<td style ="background-color: #3552f2; text-align: center; font-size: 16px; color: #fff;">
<p>© 2016. All rights reserved.</p>
</td>
</tr>
</tbody>
</table>
</body>';
$mail = new PHPMailer;
$mail->isSMTP();
// $mail->SMTPDebug = 2;
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = $emailAddress;
$mail->Password = $password;
$mail->setFrom('noreply@hrms.com', 'HRMS');
$mail->addReplyTo('johndoe@gmail.com', 'HRMS');
$mail->addAddress($email);
$mail->Subject = $subject;
$mail->msgHTML($message);
if (!$mail->send()) {
// $error = "Mailer Error: " . $mail->ErrorInfo;
// echo '<script>alert("'.$error.'");</script>';
return false;
}else {
$query = 'Update employee_has_credentials set status = '.self::STATUS_INACTIVE.' where id= '.$id.'';
$result = $this->con->prepare($query);
$result->execute(array($id));
if($result->rowCount()){
return true;
}else{
return false;
}
}
require'../extensions/phpmailer/phpmailerautoad.php';
$emailAddress='SampleEmail';
$password='Emailpassword';
$subject='员工门户邀请';
$message='1
邀请
HRMS DHVTSU
对不起,您的帐户已停用。
©2016年。保留所有权利。
';
$mail=新的PHPMailer;
$mail->isSMTP();
//$mail->SMTPDebug=2;
$mail->SMTPOptions=array(
“ssl”=>数组(
“验证对等方”=>false,
'verify_peer_name'=>false,
“允许自签名”=>true
)
);
$mail->Host='smtp.gmail.com';
$mail->Port=587;
$mail->SMTPSecure='tls';
$mail->SMTPAuth=true;
$mail->Username=$emailAddress;
$mail->Password=$Password;
$mail->setFrom('noreply@hrms.com","人力资源管理系统",;
$mail->addReplyTo('johndoe@gmail.com","人力资源管理系统",;
$mail->addAddress($email);
$mail->Subject=$Subject;
$mail->msgHTML($message);
如果(!$mail->send()){
//$error=“Mailer error:”.$mail->ErrorInfo;
//回显“警报(“.$error.”;”;
返回false;
}否则{
$query='Update employee_拥有_凭证集状态='。self::status_INACTIVE。'where id='。$id';
$result=$this->con->prepare($query);
$result->execute(数组($id));
如果($result->rowCount()){
返回true;
}否则{
返回false;
}
}
可能重复使用该代码,它将解决您的问题,因为您尚未添加以下代码:
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php'
或者转到上面的链接,您可以从该答案中看到更多描述。。免费主机很可能会阻止出站SMTP。在与gmail通话时,您永远不需要禁用证书验证-您可能需要更新您的CA证书,如故障排除指南中所述。您正在尝试从noreply@hrms.com尝试使用Gmail SMTP,我想你做不到,尝试使用主机的SMTP,我不确定这是否是问题所在,但我希望它能帮助你尝试使用SparkPost而不是GMail——如果587被你的免费主机提供商阻止,他们会在端口2525上提供连接。