How to change from-address when using gmail smtp server

后端 未结 6 630
一向
一向 2020-11-22 12:24

I want to send an email from A to B,with HEADER and CONTENT through gmail.

How to do that by PHP?<

6条回答
  •  失恋的感觉
    2020-11-22 13:05

    Unlike everyone else, I'll take the plunge and make the assumption that by letters you mean emails...

    But I'm not sure what you are getting at when you mention that it should include "Headers and Content". Do you want to forward emails? Do you want the emails from A to appear as though they came from B's gmail account in the headers? Are you building some sort of gmail client?

    The easiest way to send an email with PHP is with the mail function. This example comes straight from their documentation:

    $to      = 'nobody@example.com';
    $subject = 'the subject';
    $message = 'hello';
    $headers = 'From: webmaster@example.com' . "\r\n" .
        'Reply-To: webmaster@example.com' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();
    
    mail($to, $subject, $message, $headers);
    

    If you want the headers to appear from A's gmail and not to simply change the from/reply to part, you'd have to use gmail as the SMTP server. I don't know if you can set that at the script level.

提交回复
热议问题