2

There is a wordpress installation installed on a cpanel account. They have a contact form on that wordpress installation that is sending using the php mail function. It is supposed to be sending like this:

noreply@cpanel_example.com -> info@cpanel_example.com

But it is sending like this, using the servers hostname with the cpanel username and the email account name.

cpanel_example@server.whm_example.com -> info@cpanel_example.com

What is causing this?

*Edit

So I added a plugin in WordPress which allowed the php mail function to send from wordpress@cpanel_example.com. I don't know how it did this though. So I feel the issue is with the default php mail function sender address.

*Edit 2 (example php code)

<?php
    $to      = 'info@cpanel_example.com'; 
    $subject = 'The test for php mail function'; 
    $message = 'Hello'; 
    $headers = 'From: noreply@cpanel_example.com' . "\r\n" . 
        'Reply-To: noreply@bcttransfers.com' . "\r\n" . 
        'X-Mailer: PHP/' . phpversion(); 
    mail($to, $subject, $message, $headers); 

*Edit 3 (wordpress plugin used that allowed the emails to be sent from wordpress@cpanel_example.com)

https://wordpress.org/plugins/wp-mail-smtp/

SETTINGS
From Email: BLANK (default address used: wordpress@bcttransfers.com)
Mailer: Default (none)
Return path: checked

closed as unclear what you're asking by dan Dec 16 '17 at 4:02

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • I am not sure this is configurable, someone smarter than me might now. I got around it by setting up a forwarder. – Steve Dec 14 '17 at 8:06
  • Can you elaborate on how you setup the forwarder? – Rob Dec 14 '17 at 8:15
  • Does your edit indicate that you found a satisfactory solution? If not, please include your PHP code so we can see how you're sending emails. Of special attention would be the from address and if you're using localhost instead of an SMTP. Doing the later would of course use the server's host name and user the script was run under. Using an SMTP with a from address allowed to relay through it is what you'd want to do, and likely what the WordPress plugin probably used. – dan Dec 16 '17 at 0:49
  • Posted the php code and the WordPress plugin used with its settings. – Rob Dec 18 '17 at 7:12
1

Rather than use the default php mail function directly sending via the webserver, you may want to configure the Wordpress site to send via SMTP. I like to use the Easy WP SMTP plugin

With the plugin enabled, your site can send emails "officially" through an SMTP enabled mail account, even it is one created in CPanel on your hosting provider. The advantage to sending via SMTP and not directly through phpmail or sendmail is mitigating the likelihood of your messages being flagged as spam (sometimes because the shared server IPs being blacklisted, other times because of overridden email headers).

  • I don't want to do that. I will have 100s of sites. I just need the php mail function to send via wordpress@domain.com – Rob Dec 15 '17 at 23:10
  • if the plugin you used has a default send from address of wordpress@cpanel_example.com, chances are- you could repurpose the module and edit the php to automatically apply info@domain.com and connect via smtp (assuming you set all the info@ account passwordss with a uniform pattern). – Anson W Han Dec 16 '17 at 3:32
  • I added some more information if that helps? – Rob Dec 18 '17 at 7:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.