Why error although it was done?
Hi,
I am using below to post a form to php in order to send email to the user.
why I keep getting error although was successfully sent? and all I get in the message is the word
error. How can I get what's the exact error and how can I fix?
This is my PHP:
- <?php
- if (isset($_SERVER['HTTP_ORIGIN']))
- {
- header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
- header('Access-Control-Allow-Credentials: true');
- header('Access-Control-Max-Age: 86400'); // cache for 1 day
- }
- include('../PHPMailer/class.phpmailer.php');
-
- $sender_name = $_POST["sender_name"];
- $sender_email = $_POST["sender_email"];
- $sender_telephone = $_POST["sender_telephone"];
- $message_title = $_POST["message_title"];
- $message_text = $_POST["message_text"];
- $unique_id = uniqid();
-
- // send email to sender
- $body = "<html dir='rtl' lang='ar'>";
- $body .= "<body>";
- $body .= "<head>";
- $body .= "<meta charset='utf-8'>";
- $body .= "</head>";
- $body .= "<b>هذه الرسالة الالكترونية تم إرسالها بواسطة الرد التلقائي لذا يرجى عدم الرد.</b><hr><br><br>";
- // $body .= "Dear " . $customer_title. " " . $customer_first_name . ",<br><br>";
- $body .= "لكم جزيل الشكر.<br><br>";
- $body .= "تم استلام رسالتكم وسنقوم بالرد عليها في أقرب وقت.<br><br>";
- $body .= "مع تحياتي,<br>";
- $body .= "نبيل يعقوب الحمر";
- $body .= "<br><br>";
- // $body .= "<a href='https://www.aromabh.com/' target='_blank'>www.aromabh.com</a>";
- $body .= "</html>";
- $body .= "</body>";
- $body = nl2br($body);
- //Create a new PHPMailer instance
- $mail = new PHPMailer();
- //Tell PHPMailer to use SMTP
- $mail->IsSMTP();
- //Enable SMTP debugging
- // 0 = off (for production use)
- // 1 = client messages
- // 2 = client and server messages
- $mail->SMTPDebug = 2;
- //Ask for HTML-friendly debug output
- $mail->Debugoutput = 'html';
- //Set the hostname of the mail server
- $mail->Host = "mail.myhost.com";
- //Set the SMTP port number - likely to be 25, 465 or 587
- $mail->Port = 587;
- //Whether to use SMTP authentication
- $mail->SMTPAuth = true;
- //Username to use for SMTP authentication
- $mail->Username = "noreply@mydomain.com";
- //Password to use for SMTP authentication
- $mail->Password = "xxxxxxxx";
- //Set who the message is to be sent from
- $mail->SetFrom("noreply@mydomain.com", "نبيل يعقوب الحمر");
- //Set who the message is to be sent to
- $mail->AddAddress($sender_email, $sender_name);
- //Replace the plain text body with one created manually
- $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
- //Attach an image file
- // $mail->AddAttachment('images/phpmailer_mini.gif');
- // $mail->AddCustomHeader($mail_header);
- //Set the subject line
- $mail->Subject = "شكرا " . " " . $sender_name . " :)";
- //Read an HTML message body from an external file, convert referenced images to embedded, convert HTML into a basic plain-text alternative body
- // $mail->MsgHTML($body);
- $mail->Body = $body;
- $mail->CharSet = 'UTF-8';
- $mail->IsHTML(true);
- //Send the message, check for errors
- if(!$mail->Send()) {
- echo "Mailer Error: " . $mail->ErrorInfo;
- } else {
- echo "Message sent!";
- }
- // send email to management
- $body = "<html dir='rtl' lang='ar'>";
- $body .= "<body>";
- $body .= "<head>";
- $body .= "<meta charset='utf-8'>";
- $body .= "</head>";
- $body .= "<b>هذه الرسالة الالكترونية تم إرسالها بواسطة الرد التلقائي لذا يرجى عدم الرد.</b><hr><br><br>";
- $body .= "Dear Mesk Staff,<br><br>";
- $body .= "<br><br><br>";
- $body .= "Best Regards,";
- $body .= "<br>";
- $body .= "Mesk Holdings";
- $body .= "<br><br>";
- $body .= "<a href='https://www.meskholdings.com/' target='_blank'>www.meskholdings.com</a>";
- $body .= "</html>";
- $body .= "</body>";
- $body = nl2br($body);
- //Create a new PHPMailer instance
- $mail = new PHPMailer();
- //Tell PHPMailer to use SMTP
- $mail->IsSMTP();
- //Enable SMTP debugging
- // 0 = off (for production use)
- // 1 = client messages
- // 2 = client and server messages
- $mail->SMTPDebug = 2;
- //Ask for HTML-friendly debug output
- $mail->Debugoutput = 'html';
- //Set the hostname of the mail server
- $mail->Host = "mail.myhost.com";
- //Set the SMTP port number - likely to be 25, 465 or 587
- $mail->Port = 587;
- //Whether to use SMTP authentication
- $mail->SMTPAuth = true;
- //Username to use for SMTP authentication
- $mail->Username = "noreply-mailer@mydomain.com";
- //Password to use for SMTP authentication
- $mail->Password = "xxxxxxxx";
- //Set who the message is to be sent from
- $mail->SetFrom("noreply@mydomain.com", $sender_name);
- // display the from name and email;
- // $mail->FromName = $_POST['txtName'] ." <" . $_POST['txtEmail'] . ">";
- //Set an alternative reply-to address
- $mail->AddReplyTo($sender_email, $sender_name);
- //Set who the message is to be sent to
- $mail->AddAddress("email@domain.com", "Jassim Rahma");
- //Replace the plain text body with one created manually
- $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
- //Attach an image file
- // $mail->AddAttachment('images/phpmailer_mini.gif');
- // $mail->AddCustomHeader($mail_header);
- //Set the subject line
- $mail->Subject = $message_title;
- //Read an HTML message body from an external file, convert referenced images to embedded, convert HTML into a basic plain-text alternative body
- // $mail->MsgHTML($body);
- $mail->Body = $body;
- $mail->CharSet = 'UTF-8';
- $mail->IsHTML(true);
- //Send the message, check for errors
- if(!$mail->Send()) {
- echo "Mailer Error: " . $mail->ErrorInfo;
- } else {
- echo "Message sent!";
- }
- ?>