• I have installed WPMail-SMTP using ‘other SMTP’ – my hosting provider – and the Test email works fine.
    I want to generate emails from within a page PHP but I have been unable to get that to work. The code I have been using is below. The ‘From’ email (‘[email protected]’) is the same as the ‘SMTP Username’ and the ‘From email:’ on the WPMail-SMTP settings form.

    Do you have any suggestions as to what I need to do to send emails from code?
    Is there any way I can get some more helpful debug info? (at the moment all I can find is the return value of wp_mail: pass or fail)

    add_filter('wp_mail_from','yoursite_wp_mail_from');
    function yoursite_wp_mail_from($content_type) {	return '[email protected]';}
    add_filter('wp_mail_from_name','yoursite_wp_mail_from_name');
    function yoursite_wp_mail_from_name($name) {return 'Admin';	}
    $to = '[email protected]';
    $subject = 'My Subject ';
    $body = '<p>The body of the email</p>';
    $headers = array('Content-Type: text/html; charset=UTF-8');
    if(wp_mail( $to, $subject, $body, $headers ))
    {echo '<p>email SENT</p>';}
    else
    {echo '<p>email FAIL</p>';};
Viewing 2 replies - 1 through 2 (of 2 total)
  • I was in the same boat – I found I was able to use the system defaults by simply not trying to set the ‘from’ address and other header information.

    $recipient = '[email protected]';
    $subject = 'my subject';
    $message = 'my message';
    wp_mail( $recipient, $subject, $message );

    That being said, if your SMTP provider allows altering the ‘From’ information (for example) then it would be nice to know how to customize this by loading the defaults and then altering, but I haven’t been able to find out how to load the defaults.

    Thread Starter davidwilbourn

    (@davidwilbourn)

    Hi Steph,
    Thanks for the suggestion. I did actually try leaving out the ‘From:’ stuff but still no joy ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘sending SMTP email from PHP’ is closed to new replies.