I have problems when I setup mail forwarding in PLESK
.
I setup a mail sending PHP script, using mail() function, but after getting errors on receiving the mails, my hosting (interserver.net
) suggested the following:
I would suggest you use
PHPMailer
with SMTP authentication to send out mails to avoid issues with mails being rejected/marked as spam when using PHPmail()
. Please check and let us know for further assistance.
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '../../PHPMailer/src/Exception.php';
require '../../PHPMailer/src/PHPMailer.php';
require '../../PHPMailer/src/SMTP.php';
ini_set("SMTP", "albavaluecentre.ro");
ini_set("smtp_port", "25");
$errorMSG = "";
$name = "";
$email = "";
$price = "";
// NAME
if (empty($_POST["name"])) {
$errorMSG = "Name is required ";
} else {
$name = $_POST["name"];
}
// EMAIL
if (empty($_POST["email"])) {
$errorMSG .= "Email is required ";
} else {
$email = $_POST["email"];
}
// Price
if (empty($_POST["price"])) {
$errorMSG .= "Price is required ";
} else {
$price = $_POST["price"];
}
$EmailTo = "office@albavaluecentre.ro ";
$Subject = "✨New Message Received from Domain Selling✨";
$headers = 'From: office@albavaluecentre.ro' . " " .
'Cc: '.$email.'' . " " .
'Bcc: '.$email.'' . " " .
'Reply-To: '.$email.'' . " " .
'X-Mailer: PHP/' . phpversion();
$Subject = '✨New Message Received ✨ Bid from Client: '.$price;
// prepare email body text
$Body = "";
$Body .= "NAME: ";
$Body .= $name;
$Body .= "<br/>";
$Body .= "EMAIL: ";
$Body .= $email;
$Body .= "<br/>";
$Body .= "PRICE: ";
$Body .= $price;
$Body .= "<br/>";
$Body .= "DOMAIN: ";
$Body .= $_SERVER['HTTP_HOST'];
$mail2 = new PHPMailer();
$mail2->isSMTP();
$mail2->isHTML(true);
$mail2->CharSet = "UTF-8";
$mail2->Host = 'albavaluecentre.ro';
$mail2->SMTPAuth = true;
$mail2->Username = 'office@albavaluecentre.ro';
$mail2->Password = 'XXX';
$mail2->SMTPSecure = 'tls';
$mail2->Port = 25;
$mail2->setFrom($email, 'BidClient');
$mail2->addAddress('office@albavaluecentre.ro', 'Bid Office');
$mail2->Subject = $Subject;
$mail2->Body = $Body;
if($mail2->send())
{
echo 'Message has been sent';
}
else
{
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail2->ErrorInfo;
}
?>
for website: link
I changed the PHP mail() to PHPMailer as suggested above to:
but I got the following errors, when I send an email from website:
- on office@albavaluecentre.ro:
a good email: https://pastebin.com/Ygv6SjxZ
and one with error: https://pastebin.com/arfzn1Ri
- on ecclesiasoft@yahoo.com:
- one email with error: https://pastebin.com/0PaJ90N7
Is the PHP code wrong or what I'm doing wrong? (sorry, but I'm a PHP newbie)