Hi,
I struggled with this one and needed the same: my piwigo site webmaster email is not accepted by my SMTP service, and I needed to edit the "From" field from which the Contact Form plugin sends an email.
I assume I'm not the only one with this problem and I found a solution. This post is outdated but the forum is still useful for future users making queries.
Edit your email and paste this code in the 'Personal Plugin' space of the 'LocalFiles Editor' plugin.
/*
// For contact forms emails only: Sends as 'myotheremail@myotherdomain.com because by default it uses pwg_mail() and then my VPS php mail (), using the default piwigo webmaster email in the FROM field, which is not an approved sender for my SMTP provider
*/
add_event_handler('before_send_mail', 'override_contact_form_from', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
function override_contact_form_from($result, $to, $args, $mail) {
// Only modify ContactForm emails
if (isset($args['subject']) && strpos($args['subject'], '[') === 0) {
// Store original sender info
$original_from = $mail->From;
$original_name = $mail->FromName;
// Override the PHPMailer From field directly
$mail->setFrom('myotheremail@myotherdomain.com', 'Myself Thatworks');
}
return $result;
}
This works for the emails sent by the Contact Form plugin.
I had the same problem for notification emails sent by Piwigo itself (e.g. a new user registers, new photos are added). The recommended approach here with the
$conf['mail_sender_email'] parameter didn't work for me on Piwigo 16.1.
I used that code instead, also saved in my Personal Plugin, inspired from the Protect Notification plugin
/*
// For piwigo-sent notifications only: Sends as 'myotheremail@myotherdomain.com because by default it uses pwg_mail() and then my VPS php mail (), using the default piwigo webmaster email in the FROM field, which is not an approved sender for my SMTP provider
*/
if (!function_exists('protect_switch_webmaster_email')) {
function protect_switch_webmaster_email($email) {
return 'myotheremail@myotherdomain.com';
}
}
add_event_handler('get_webmaster_mail_address', 'protect_switch_webmaster_email');
I hope that helps future watchers!
This could also be integrated in the Piwigo config itself, or the Contact Form plugin itself, since the current documentation at
https://doc.piwigo.org/customizing-your-gallery/add-pages-to-piwigo-gallery reads "If you don't manage to solve the issue, we recommend you uninstall Contact Form."