My mailer is not functioning, I have tried every means and I’m not that good with php, please help #2686
Replies: 20 comments 45 replies
-
Please help |
Beta Was this translation helpful? Give feedback.
-
I will appreciate it if you can please help me to arrange the code please |
Beta Was this translation helpful? Give feedback.
-
Hello I have arrange the code and the page is now showing but there is a problem it seems like the smtp did not work please check the code please I will send you the new code |
Beta Was this translation helpful? Give feedback.
-
<?php
/**
* This example shows making an SMTP connection with authentication.
*/
//Import the PHPMailer class into the global namespace
use PHPMailer\PHPMailer\PHPMailer;
//send email
// Turn this off when debugging and devloping
//error_reporting(0);
// Mail values
$fromName = trim($_POST["fromName"]);
$fromEmail = trim($_POST["fromEmail"]);
$toEmail = trim($_POST["toEmail"]);
$cc = trim($_POST["cc"]);
$bcc = trim($_POST["bcc"]);
$subjectLine = trim($_POST["subjectLine"]);
// Message Values
$richMessageText = $_POST["richMessageText"];
$rawMessageText = $_POST["rawMessageText"];
$message = "";
$messageErrorSet = false;
// Attatchment
$path = "uploads/";
$path = $path . basename( $_FILES['attachment']['name']);
$fileTempName = $_FILES['attachment']['tmp_name'];
$fileUploaded = 0; // 0 = no upload, 1 = upload success, 2 = upload failure
$attatchError = "";
// File attacher + error handler
if (!empty($fileTempName)) { //checks to see if a file was attatched
// Attempt to upload file
if(move_uploaded_file($fileTempName, $path)) {
$fileUploaded = 1; // success
} else {
$fileUploaded = 2; // failure
$attatchError = "Your message was not sent. There was an error uploading your attachment. Make sure that your php.ini file within your web server allows for file uploads, and that it allows for the upload size of your attatched file. Check out <a href='https://mediatemple.net/community/products/dv/204403894/how-can-i-edit-the-php.ini-file'>this guide</a> to make changes to the php.ini file.";
}
}
// Store the right message body as the $message var
// If value exists for ritch text but not raw sore rich message text as $message
if(!empty($richMessageText) && empty($rawMessageText)) {
$message = $richMessageText;
}
// If value exists for raw text but not ritch store raw message text as $message
elseif (empty($richMessageText) && !empty($rawMessageText)) {
$message = $rawMessageText;
// If values exist for both then throw an error and update the error text
} elseif (!empty($richMessageText) && empty(!$rawMessageText)){
$messageErrorText = "Your message was not sent. You have entered content into both the rich text editor and the raw text. Please return to the form and only use one.";
$messageErrorSet = true;
} else {
$messageErrorText = "Your message was not sent. It appears as if you did not enter any content into the message text area. Make sure that you go back and input content here.";
$messageErrorSet = true;
}
//send email
require_once "PHPMailer/PHPMailer.php";
require_once 'PHPMailer/Exception.php';
// This code was brorrowed from the PHPMailer github page as an example useage
$mail = new PHPMailer(true);
try {
$mail = new PHPMailer();
$mail->IsSMTP(true);
$mail->Mailer = 'smtp';
$mail->Host = 'localhost';
$mail->Host = "mail.privatemail.com";
$mail->SMTPAuth = true;
$mail->SMTPAutoTLS = true;
$mail->Port = 465;
$mail->Username = "lfreeman@ceonacch.org";
$mail->Password = "blre"; // SMTP password
//Recipients
$mail->setFrom($fromEmail, $fromName);
$mail->addAddress($toEmail);
// Add cc to header if there is a value in either
if (!empty($cc)) {
$mail->addCC($cc);
}
// Add bcc to header if there is a value
if (!empty($bcc)) {
$mail->addBCC($bcc);
}
//Attachments
if (!empty($fileTempName)) { //checks to see if a file was attatched
$mail->addAttachment($path); // Add attachments
}
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subjectLine;
$mail->Body = $message;
// Send Mail using values
if ($fileUploaded == 2) {
//dont send message
} else {
$mail->send();
//SUCESS mailed message
echo "
<div class=\"col-md-6 offset-md-3\">
<div class=\"alert alert-success\" role=\"alert\">
<strong>Email Sent!</strong> Email has been sent. Keep in mind that if you used the rich text editor, the message may appear slightly different in the actual email!
</div>
</div>
";
}
// Failure message sent
} catch (Exception $e) {
echo "
<div class=\"col-md-6 offset-md-3\">
<div class=\"alert alert-danger\" role=\"alert\">
<p><strong>Awe Snap! </strong>Your message was not sent. Something went wrong with the PHP mail() function and is returning a value of FALSE. Chances are if you are seeing this message it means that it could not reach out to the SMTP server. Make sure that the webserver you are running is configured to also point to a mail server.</p>
</div>
</div>
";
}
// SUCESS AND ERROR MESSAGES
// If message error is true display error
if ($messageErrorSet == true) {
echo "
<div class=\"col-md-6 offset-md-3\">
<div class=\"alert alert-danger\" role=\"alert\">
<p><strong>Awe Snap! </strong>".$messageErrorText."</p>
</div>
</div>
";
}
// If attat error
if ($fileUploaded == 2){
echo "
<div class=\"col-md-6 offset-md-3\">
<div class=\"alert alert-danger\" role=\"alert\">
<p><strong>Awe Snap! </strong>" . $attatchError . "</p>
</div>
</div>
";
}
?> |
Beta Was this translation helpful? Give feedback.
-
Thanks I have added this $mail->SMTPSecure = 'ssl'; what smtp settings do I need when sending through port 25? |
Beta Was this translation helpful? Give feedback.
-
Ok thanks, it seems like the smtp settings is blocking the rest data from submitting because if I click send this is the response It will show blank but if I refresh the page my hiting enter on the url bar this is the response Awe Snap! Your message was not sent. It appears as if you did not enter any content into the message text area. Make sure that you go back and input content here. |
Beta Was this translation helpful? Give feedback.
-
Please what do you suggest could be the fault because the fault? |
Beta Was this translation helpful? Give feedback.
-
I had to arrange my code again it’s working now |
Beta Was this translation helpful? Give feedback.
-
But the messages are not delivering in inbox but it only shows sent but nothing was delivered to my mailbox |
Beta Was this translation helpful? Give feedback.
-
Nothing in spam folder, I will paste you the code to see |
Beta Was this translation helpful? Give feedback.
-
<?php
/**
* This example shows making an SMTP connection with authentication.
*/
//Import the PHPMailer class into the global namespace
use PHPMailer\PHPMailer\PHPMailer;
require_once "PHPMailer/PHPMailer.php";
require_once 'PHPMailer/Exception.php';
// This code was brorrowed from the PHPMailer github page as an example useage
$mail = new PHPMailer(true);
try {
$mail = new PHPMailer();
$mail->IsSMTP(true);
$mail->Mailer = 'smtp';
$mail->Host = 'mail.privateemail.com';
$mail->SMTPSecure = 'tls';
$mail->Host = "mail.privatemail.com";
$mail->SMTPAuth = true;
$mail->SMTPAutoTLS = true;
$mail->Port = 25;
$mail->Username = "lfreeman@bb.org";
$mail->Password = "mme";
//Recipients
$mail->setFrom($fromEmail, $fromName);
$mail->addAddress($toEmail);
// Add cc to header if there is a value in either
if (!empty($cc)) {
$mail->addCC($cc);
}
// Add bcc to header if there is a value
if (!empty($bcc)) {
$mail->addBCC($bcc);
}
//Attachments
if (!empty($fileTempName)) { //checks to see if a file was attatched
$mail->addAttachment($path); // Add attachments
}
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subjectLine;
$mail->Body = $message;
// Send Mail using values
if ($fileUploaded == 2) {
//dont send message
} else {
$mail->send();
//SUCESS mailed message
echo "
<div class=\"col-md-6 offset-md-3\">
<div class=\"alert alert-success\" role=\"alert\">
<strong>Email Sent!</strong> Email has been sent. Keep in mind that if you used the rich text editor, the message may appear slightly different in the actual email!
</div>
</div>
";
}
// Failure message sent
} catch (Exception $e) {
echo "
<div class=\"col-md-6 offset-md-3\">
<div class=\"alert alert-danger\" role=\"alert\">
<p><strong>Awe Snap! </strong>Your message was not sent. Something went wrong with the PHP mail() function and is returning a value of FALSE. Chances are if you are seeing this message it means that it could not reach out to the SMTP server. Make sure that the webserver you are running is configured to also point to a mail server.</p>
</div>
</div>
";
}
// SUCESS AND ERROR MESSAGES
// If message error is true display error
if ($messageErrorSet == true) {
echo "
<div class=\"col-md-6 offset-md-3\">
<div class=\"alert alert-danger\" role=\"alert\">
<p><strong>Awe Snap! </strong>".$messageErrorText."</p>
</div>
</div>
";
}
// If attat error
if ($fileUploaded == 2){
echo "
<div class=\"col-md-6 offset-md-3\">
<div class=\"alert alert-danger\" role=\"alert\">
<p><strong>Awe Snap! </strong>" . $attatchError . "</p>
</div>
</div>
";
}
// Turn this off when debugging and devloping
//error_reporting(0);
// Mail values
$fromName = trim($_POST["fromName"]);
$fromEmail = trim($_POST["fromEmail"]);
$toEmail = trim($_POST["toEmail"]);
$cc = trim($_POST["cc"]);
$bcc = trim($_POST["bcc"]);
$subjectLine = trim($_POST["subjectLine"]);
// Message Values
$richMessageText = $_POST["richMessageText"];
$rawMessageText = $_POST["rawMessageText"];
$message = "";
$messageErrorSet = false;
// Attatchment
$path = "uploads/";
$path = $path . basename( $_FILES['attachment']['name']);
$fileTempName = $_FILES['attachment']['tmp_name'];
$fileUploaded = 0; // 0 = no upload, 1 = upload success, 2 = upload failure
$attatchError = "";
// File attacher + error handler
if (!empty($fileTempName)) { //checks to see if a file was attatched
// Attempt to upload file
if(move_uploaded_file($fileTempName, $path)) {
$fileUploaded = 1; // success
} else {
$fileUploaded = 2; // failure
$attatchError = "Your message was not sent. There was an error uploading your attachment. Make sure that your php.ini file within your web server allows for file uploads, and that it allows for the upload size of your attatched file. Check out <a href='https://mediatemple.net/community/products/dv/204403894/how-can-i-edit-the-php.ini-file'>this guide</a> to make changes to the php.ini file.";
}
}
// Store the right message body as the $message var
// If value exists for ritch text but not raw sore rich message text as $message
if(!empty($richMessageText) && empty($rawMessageText)) {
$message = $richMessageText;
}
// If value exists for raw text but not ritch store raw message text as $message
elseif (empty($richMessageText) && !empty($rawMessageText)) {
$message = $rawMessageText;
// If values exist for both then throw an error and update the error text
} elseif (!empty($richMessageText) && empty(!$rawMessageText)){
$messageErrorText = "Your message was not sent. You have entered content into both the rich text editor and the raw text. Please return to the form and only use one.";
$messageErrorSet = true;
} else {
$messageErrorText = "Your message was not sent. It appears as if you did not enter any content into the message text area. Make sure that you go back and input content here.";
$messageErrorSet = true;
}
?> |
Beta Was this translation helpful? Give feedback.
-
You did it you did it it worked |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot |
Beta Was this translation helpful? Give feedback.
-
I really do appreciate |
Beta Was this translation helpful? Give feedback.
-
Where can I insert this code ? $headers .= "X-Sender: <$from>\n"; |
Beta Was this translation helpful? Give feedback.
-
Can I change that xmailer to another mailer agent? |
Beta Was this translation helpful? Give feedback.
-
Please I need your help this last time. This is my code below I want PHPMailer send email with multiple SMTP hosts. I don’t know how to do it or the right place to add it or the right code for it. I will appreciate your help on this issue. `$mail = new PHPMailer(true); try { $mail = new PHPMailer(); ` |
Beta Was this translation helpful? Give feedback.
-
My mailer is not functioning, I have tried every means and I’m not that good with php
Beta Was this translation helpful? Give feedback.
All reactions