• The APS Catalog has been deprecated and removed from all Plesk Obsidian versions.
    Applications already installed from the APS Catalog will continue working. However, Plesk will no longer provide support for APS applications.
  • Please be aware: with the Plesk Obsidian 18.0.78 release, the support for the ngx_pagespeed.so module will be deprecated and removed from the sw-nginx package.

Question Changing programmaticaly (PHP - phpMailer) the from of an email doesn't work

nvincent

New Pleskian
Server operating system version
Debian GNU/Linux 11 (bullseye)
Plesk version and microupdate number
18.0.77
Hello,

I've got this simple test code using phpMailer on my Plesk server :
PHP:
//Create a new PHPMailer instance
$mail = new PHPMailer\PHPMailer\PHPMailer();
//Set who the message is to be sent from
$mail->setFrom('[email protected]', 'Contact D1');
//Set an alternative reply-to address
$mail->addReplyTo('[email protected]', 'Contact D1');
//Set who the message is to be sent to
$mail->addAddress('[email protected]', 'Contact D2');
//Set the subject line
$mail->Subject = 'PHPMailer mail() test';
//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('<p>hello</p>');
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
// $mail->addAttachment('images/phpmailer_mini.png');

//send the message, check for errors
if (!$mail->send()) {
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message sent!';
}

And in mail log I've got the following error :
Apr 15 15:52:49 plesk msmtp: host=smtp.server.com tls=on auth=on user=smtp.user from=[email protected] recipients=[email protected] smtpstatus=501 smtpmsg='501 5.1.7 The specified sender domain has not been linked.' errormsg='envelope from address [email protected] not accepted by the server' exitcode=EX_DATAERR

As you can see, the "from" isn't the one I've written in the phpMailer code, it seems to be rewrite by Plesk.
How can I fix this, please ?
 
If I recall correctly, the way the mail function is handled is heavily wrapped by Plesk. I've personally just update the config to use using SMTP and reference itself to send the emails but you could also go to the domain in question, go to PHP Settings and under additional configuration directive add:

PHP:
sendmail_path = "/usr/sbin/sendmail -t -i -f [email protected]"

This would force any php scripts utilizing sendmail on that domain to use [email protected].
 
Back
Top