我已经实现了通过PHPMailer发送电子邮件,并且当项目在本地服务器的本地主机上发送电子邮件时,发送它们没有问题,但是现在我在Web服务器上拥有了该项目发送电子邮件不再有效,我希望有人能帮我了解我做错了什么,或者在项目实施后有必要进行更改。
经过研究,我认为问题可能出在我正在使用的服务器配置上,这是Amazon Web Services Lightsail实例上的LAMP Bitnami应用程序。
这是我用来发送电子邮件的代码:
<?php
error_reporting(0);
// INFORMATION
if(isset($_POST['valor'])) {
$valor = $_POST['valor'];
}
$tiempo = time();
$codigo = $valor + $tiempo;
$reservas = ControladorReservas::ctrMostrarReservas($valor);
foreach ($reservas as $reserva) {
$id = $reserva['id'];
$correo = $reserva['correo'];
$nombre = $reserva['nombre_reserva'];
$establecimiento = $reserva['establecimiento'];
$fecha = $reserva['fecha_reserva'];
$hora = $reserva['hora_reserva'];
}
// END OF RECEIVING INFORMATION
$titulo = 'Su reserva en / Your booking at '. $establecimiento .' ha sido confirmada / has been confirmed';
$cuerpo = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Demystifying Email Design</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body style="margin: 0; padding: 0;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="padding: 10px 0 30px 0;">
<table align="center" border="0" cellpadding="0" cellspacing="0" width="600" style="border: 1px solid #cccccc; border-collapse: collapse;">
<tr>
<td bgcolor="#ffffff" style="padding: 40px 30px 40px 30px;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="color: #153643; font-family: Arial, sans-serif; font-size: 24px;">
<b>Estimado / Dear ' . $nombre . ',</b>
</td>
</tr>
<tr>
<td style="padding: 20px 0 30px 0; color: #153643; font-family: Arial, sans-serif; font-size: 16px; line-height: 20px;">
<p> Su reservacion para '. $establecimiento .' el dia '. $fecha .' a las '. $hora .' horas HA SIDO CONFIRMADA EXITOSAMENTE </p>
<p> Your booking for '. $establecimiento .' the day '. $fecha .' at '. $hora .' hours HAS BEEN CONFIRMED SUCCESSFULLY </p>
<h3> Su codigo de reserva es / Your booking code is: ' . $codigo . '</h3>
<p> Recuerde proporcionar su codigo de reserva para hacer valido su regalo </p>
<p> Remeber to proporcionate your booking code to make your gift valid </p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#4ECDC4" style="padding: 30px 30px 30px 30px;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="color: #ffffff; font-family: Arial, sans-serif; font-size: 14px;" width="75%">
® Rede, 2019<br/>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
';
require_once('PHPMailer/PhpMailerAutoload.php');
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = '465';
$mail->isHTML();
$mail->Username = 'correo@correo.com';
$mail->Password = "pass01";
$mail->SetFrom('prueba@quis.org');
//Estas 3 siguientes son personalizadas
$mail->Subject = $titulo; //email subject
$mail->Body = $cuerpo; //email body
$mail->AddAddress($correo); //receiver
$mail->Send();
?>
已经尝试更改:
$ mail-> SMTPAuth = true; $ mail-> SMTPSecure ='ssl';
为假,因为在其他文章中我读到,如果您的域没有ssl证书,这可能是个问题。
真的希望可以帮助我解决这个问题,或者知道我在做错什么。
谢谢!