How to send an email in PHP reliably?

前端 未结 4 1579
闹比i
闹比i 2021-01-24 11:07

i am learning how to send an email.i have installed appserver and in files php.ini-dist and php.ini-recommended i did the following changes

SMTP=localhost

send         


        
相关标签:
4条回答
  • 2021-01-24 11:41

    As jhominal points out, the php.ini files you've modified are just examples. You'll have to find out where the php.ini is for your distribution and modify it.

    As mentioned by others, you can set a custom from header. However, if you don't set sendmail_from in php.ini you'll have to remember to always set it.

    At any rate, here is a pretty good article/tutorial on sending email with PHP's mail() function:

    http://articles.sitepoint.com/article/advanced-email-php

    0 讨论(0)
  • 2021-01-24 11:54

    I believe you have at least two problems:

    1. I am guessing that php.ini-recommended and php.ini-dist are respectively an example and a template configuration files; modifications to them may not impact the "real" php.ini, currently used by your instance of PHP. Use phpinfo() to make sure that your configuration is correct.
    2. Spam filters. Jeff Atwood has a pretty good blog post about implementing the checks that servers do when checking if your email message is spammy. Don't forget:

    Just because you send an email doesn't mean it will arrive.

    0 讨论(0)
  • 2021-01-24 11:55

    It could be simplier to use an external library to send mails, as http://swiftmailer.org/ instead of playing with php.ini

    It's never good to be php.ini dependant.

    0 讨论(0)
  • 2021-01-24 11:55

    Try this: This worked for me in my site.

    $email = "your e-mail address";
    $myname = "name";
    $mymail = "reply Address";
        $subject = "SUBJECT LINE";
        $body = "TEXT GOES HERE";
        $headers = "Content-Type: text/plain; charset=us-ascii\nFrom: $myname <$mymail>\n
        Reply-To: <$mymail>\nBCC:<$mymail>\nReturn-Path: <$mymail>\nX-Mailer: PHP";
    
                //send the email
                if ($email != "") { 
                    mail($email,$subject,$body,$headers); 
                }   
    
    0 讨论(0)
提交回复
热议问题