欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

phpmailer发送gmail邮件实例详解

程序员文章站 2022-10-18 09:31:29
复制代码 代码如下:phpmailer - smtp (gmail) basic test<...</div> <div class="content"> <div class="codetitle"> <span><a style="cursor: pointer" data="24869" class="copybut" id="copybut24869" onclick="docopy('code24869')" target="_blank" rel="nofollow" href="/default/index/url?u=aHR0cHM6Ly93d3cuMTBxaWFud2FuLmNvbQ=="><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code24869"> <br><html><br><head><br><title>phpmailer - smtp (gmail) basic test</title><br></head><br><body><br><?php<br>//error_reporting(e_all);<br>error_reporting(e_strict);<br>date_default_timezone_set('america/toronto');<br>require_once('../class.phpmailer.php');<br>//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded<br>$mail             = new phpmailer();<br>$body             = file_get_contents('contents.html');<br>$body             = eregi_replace("[\]",'',$body);<br>$mail->issmtp(); // telling the class to use smtp<br>$mail->host       = "mail.gmail.com"; // smtp server<br>$mail->smtpdebug  = 2;                     // enables smtp debug information (for testing)<br>                                           // 1 = errors and messages<br>                                           // 2 = messages only<br>$mail->smtpauth   = true;                  // enable smtp authentication<br>$mail->smtpsecure = "ssl";                 // sets the prefix to the servier<br>$mail->host       = "smtp.gmail.com";      // sets gmail as the smtp server<br>$mail->port       = 465;                   // set the smtp port for the gmail server<br>$mail->username   = "***@gmail.com";  // gmail username<br>$mail->password   = "***";            // gmail password<br>$mail->setfrom('****@gmail.com', 'first last');<br>$mail->addreplyto("***@gmail.com","first last");<br>$mail->subject    = "phpmailer test subject via smtp (gmail), basic";<br>$mail->altbody    = "to view the message, please use an html compatible email viewer!"; // optional, comment out and test<br>$mail->msghtml($body);<br>$address = "***@gmail.com";<br>$mail->addaddress($address, "john doe");<br>$mail->addattachment("images/phpmailer.gif");      // attachment<br>$mail->addattachment("images/phpmailer_mini.gif"); // attachment<br>if(!$mail->send()) {<br>  echo "mailer error: " . $mail->errorinfo;<br>} else {<br>  echo "message sent!";<br>}<br>?><br></body><br></html> <br> </div> </div> <div class="info-pre-next"> <p> 上一篇: <a href="/article/1883268.html"> 有事求人说个笑话吧 </a> </p> <p> 下一篇: <a href="/article/1883270.html"> 抱住土豪不要走 </a> </p> </div> <div class="wz_tuijian"> <p> 推荐阅读 </p> <ul> <li> <a href="/article/2177572.html" target="_blank" title="PHP使用gearman进行异步的邮件或短信发送操作详解"> <h2> PHP使用gearman进行异步的邮件或短信发送操作详解 </h2> </a> </li> <li> <a href="/article/2159474.html" target="_blank" title="ThinkPHP利用PHPMailer实现邮件发送实现代码"> <h2> ThinkPHP利用PHPMailer实现邮件发送实现代码 </h2> </a> </li> <li> <a href="/article/2158902.html" target="_blank" title="java 发送邮件的实例代码(可移植)"> <h2> java 发送邮件的实例代码(可移植) </h2> </a> </li> <li> <a href="/article/2142202.html" target="_blank" title="详解Python发送邮件实例"> <h2> 详解Python发送邮件实例 </h2> </a> </li> <li> <a href="/article/2135181.html" target="_blank" title="Node.js使用NodeMailer发送邮件实例代码"> <h2> Node.js使用NodeMailer发送邮件实例代码 </h2> </a> </li> <li> <a href="/article/2135171.html" target="_blank" title="php多种形式发送邮件(mail qmail邮件系统 phpmailer类)"> <h2> php多种形式发送邮件(mail qmail邮件系统 phpmailer类) </h2> </a> </li> <li> <a href="/article/2135071.html" target="_blank" title="Python读取ini文件、操作mysql、发送邮件实例"> <h2> Python读取ini文件、操作mysql、发送邮件实例 </h2> </a> </li> <li> <a href="/article/2133532.html" target="_blank" title="phpmailer在服务器上不能正常发送邮件的解决办法"> <h2> phpmailer在服务器上不能正常发送邮件的解决办法 </h2> </a> </li> <li> <a href="/article/2131886.html" target="_blank" title="thinkphp使用phpmailer发送邮件的方法"> <h2> thinkphp使用phpmailer发送邮件的方法 </h2> </a> </li> <li> <a href="/article/2127718.html" target="_blank" title="C# 服务器发送邮件失败实例分析"> <h2> C# 服务器发送邮件失败实例分析 </h2> </a> </li> </ul> </div> </article> </div> </main> <footer><div class="box"><div class="ft_nav"><div class="ft_about"><p>关于网站</p><ul><li><a href="/sitemap.xml" target="_blank" title="网站地图">网站地图</a></li><li><a href="/list/2/" title="最新程序员文章站">最新程序员文章站</a></li></ul></div><div class="ft_contact"><ul><li>本站所有数据收集于网络如有侵犯到您的权益,请联系我们进行下架处理。</li><li class="email_show"></li></ul></div></div><div class="copyright"><div class="cr_left"><p> 备案号:<a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">粤ICP备20058927号</a></p><p>© Copyright © 2020-2022 www.superweb999.com 程序员文章站. </p></div></div></div></footer> </body> </html>