简体   繁体   中英

How to send email from local machine to gmail?

I am just learning php and it's my first question on this site. Hope, you will help me. I just want to send Email from my local machine to gmail. I have tried but didn't got any success. Please help How to do this. my code is form processing return mail( $message['to'], join("\\n", $headers)) }; ?>

You will want the mail() function see: php.net/manual/en/function.mail.php

mail('kushagra@gmail.com', 'My First Email', 'The body of my email');

You will need a mail server running on your local machine such as Postfix for *nix or Pegasus for Windows.

If you do not have the ability run a mail server on your machine then you might need to use a PHP class that allows you to connect to an SMTP server such as SwiftMailer or PHPMailer .

Be aware though that a lot of ISPs will block connections on port 25 (SMTP) to protect against spamming (see my encounter of this with Optus a few years ago http://blog.simonholywell.com/post/374223466/optus-cable-port-25-smtp ). If they are blocking it then you will need to use their SMTP server.

There is a tool linked in my blog post above which will allow you to determine if it is blocked or not see: http://www.zoneedit.com/smtp.html

The standard builtin function to send mail in PHP is mail():

http://php.net/mail

Unfortunately, you cannot use it with Gmail since Gmail requires two security measures that are not supported by good old mail():

  • Authentication
  • Encryption

You need to find and download a third-party library. Popular choices include PHPMailer and Swift Mailer .

如果您查看此PHPMailer示例 ,则可以将Gmail用作SMTP服务器,将邮件发送到您自己的帐户-保证送达!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM