我需要发送一封包含PHPMailer的电子邮件,在尝试获取表单元素时,无法发送它,但如果我使用示例代码,则它可以正常工作。
另外,php没有发送错误,因此代码执行正确,我不明白为什么会这样。
这是我的php代码:
alternative
另外,我必须提到我的表单是在不同的php文件中。
答案 0 :(得分:0)
将您的代码更改为此代码并查看其是否有效。
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/SMTP.php';
$mail = new PHPMailer(true);
//Obtener datos
try {
$name = $_POST['name'];
$lastName = $_POST['lastName'];
$email = $_POST['email'];
$speciality = $_POST['speciality'];
$title = $_POST['title'];
$phone = $_POST['phone'];
$adress = $_POST['adress'];
$phone = $_POST['phone'];
$cellphone = $_POST['cellphone'];
$state = $_POST['state'];
$colony = $_POST['colony'];
$rfc = $_POST['rfc'];
//Luego tenemos que iniciar la validación por SMTP:
// $mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = "krishna.hosting-mexico.net";
$mail->Username = "registros@aliar.svri.org.mx"; .
$mail->Password = "xxxx";
$mail->Port = 465;
$mail->From = "registros@aliar.svri.org.mx";
$mail->FromName = "Registros Aliar";
$mail->AddAddress("mauricioandres288@gmail.com");
//Content
// $mail->isHTML(true); // Set email format to HTML
// $mail->Subject = 'Here is the subject';
// $mail->Body = 'This is the HTML message body <b>in bold!</b>';
// $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
// $mail->send();
$mail->IsHTML(true); // El correo se envía como HTML
$mail->Subject = "Nuevo registro de" . $name . " " . $lastName; // Este es el titulo del email.
$body="";
$body .= "Nuevo registro de" . $name . " " . $lastName;
$body .= "<br><h4>Datos personales: </h4>";
$body .= "<ul><li>" . $name . "</li>";
$body .= "<li>" . $lastName . "</li>";
$body .= "<li>" . $email . "</li>";
$body .= "<li>" . $speciality . "</li>";
$body .= "<li>" . $title . "</li>";
$body .= "<li>" . $phone . "</li>";
$body .= "<li>" . $adress . "</li>";
$body .= "<li>" . $phone . "</li>";
$body .= "<li>" . $cellphone . "</li>";
$$body .= "<li>" . $state . "</li>";
$body .= "<li>" . $colony . "</li>";
$body .= "<li>" . $rfc . "</li></ul>";
$mail->Body = $body;
$mail->send();
}
catch (Exception $e) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
?>