how to send email from php mail function using gmail account?
I hav开发者_Go百科e to send email from my gmail account using php mail() function. I have read the phpmailer but I don't want to include any external apis. Please suggest.
Thanks in advance.
You cannot use mail()
to send email with your Gmail account, you'll have to use something that talks to Gmail SMTP server directly. So you're stuck with writing your own or using one of the availiable libraries, the most commonly known are:
- Swift Mailer
- PHP Mailer
- Zend Mail
Assuming mail() works on your server, just:
<?PHP
mail($to,$subj,$body,"From: yourname@gmail.com\r\n");
should do it.
The reason this works is that the "From" address on an email is really very much like the return address on a snail-mail envelope. I can write a letter and mail it from my home, with a return address for my office.
精彩评论