2017-11-06 20 views
0

フォーム要素を取得しようとすると、PHPMailerで電子メールを送信する必要がありますが、サンプルコードを使用すると完全に動作します。PHPMailerがカスタムボディで電子メールを送信しない

また、phpはエラーを送信しないので、コードが正しく実行されるため、なぜこのようなことが起こるのかわかりません。

<?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 = "[email protected]"; . 
$mail->Password = "xxxx"; 
$mail->Port = 465; 
$mail->From = "[email protected]"; 
$mail->FromName = "Registros Aliar"; 
$mail->AddAddress("[email protected]"); 


//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. 
    $mail->Body = "Nuevo registro de" . $name . " " . $lastName; 
    $mail->Body .= "<br><h4>Datos personales: </h4>"; 
    $mail->Body .= "<ul><li>" . $name . "</li>"; 
    $mail->Body .= "<li>" . $lastName . "</li>"; 
    $mail->Body .= "<li>" . $email . "</li>"; 
    $mail->Body .= "<li>" . $speciality . "</li>"; 
    $mail->Body .= "<li>" . $title . "</li>"; 
    $mail->Body .= "<li>" . $phone . "</li>"; 
    $mail->Body .= "<li>" . $adress . "</li>"; 
    $mail->Body .= "<li>" . $phone . "</li>"; 
    $mail->Body .= "<li>" . $cellphone . "</li>"; 
    $mail->Body .= "<li>" . $state . "</li>"; 
    $mail->Body .= "<li>" . $colony . "</li>"; 
    $mail->Body .= "<li>" . $rfc . "</li></ul>"; 
    // $mail->Body = $body; 

    $mail->send(); 
} 
catch (Exception $e) { 
    echo 'Message could not be sent.'; 
    echo 'Mailer Error: ' . $mail->ErrorInfo; 
} 

?> 

はまた、私は私のフォームは異なるPHPファイルであることを言及する必要があります。

は、ここに私のPHPコードです。

答えて

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 = "[email protected]"; . 
$mail->Password = "xxxx"; 
$mail->Port = 465; 
$mail->From = "[email protected]"; 
$mail->FromName = "Registros Aliar"; 
$mail->AddAddress("[email protected]"); 


//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; 
} 

?> 
+0

デバッグを有効にするには、いいえ、それは働いていない、とデバッグがOK ...奇妙 –

+0

$ mail-> SMTPDebugを使用...それは今、おかげで動作します –

+0

示さなかった、それが送信される電子メールのために5分かかった= 3 –

関連する問題