<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PHPMailer - itOffside.com | บทความการเขียนโปรแกรม เรื่องราวข้อมูลเทคโนโลยี</title>
	<atom:link href="https://www.itoffside.com/tag/phpmailer/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.itoffside.com</link>
	<description>ข้อมูลข่าวสารและเรื่องราวบนโลกของไอทีที่ ล้ำหน้า พร้อมสาระการเขียนโปรแกรมคอมพิวเตอร์</description>
	<lastBuildDate>Tue, 13 Jan 2015 17:13:14 +0000</lastBuildDate>
	<language>th</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.5</generator>

<image>
	<url>https://www.itoffside.com/wp-content/uploads/2020/04/cropped-favicon-96x96-1-32x32.png</url>
	<title>PHPMailer - itOffside.com | บทความการเขียนโปรแกรม เรื่องราวข้อมูลเทคโนโลยี</title>
	<link>https://www.itoffside.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>การส่งอีเมล์ด้วย PHPMailer (โดยส่งผ่านอีเมล์ Gmail SMTP)</title>
		<link>https://www.itoffside.com/how-to-use-phpmailer-gmail-smtp/</link>
					<comments>https://www.itoffside.com/how-to-use-phpmailer-gmail-smtp/#comments</comments>
		
		<dc:creator><![CDATA[Onmobile]]></dc:creator>
		<pubDate>Tue, 13 Jan 2015 17:10:11 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[PHPMailer]]></category>
		<guid isPermaLink="false">https://www.itoffside.com/?p=2435</guid>

					<description><![CDATA[<p>PHPMailer เป็น Class ที่ถูกพัฒนาขึ้นในการส่งอีเมล์ เพื่อความสะดวกสบายในการเรียกใช้งานซึ่งโดยปกติทาง PHP มีฟังก์ชั่นการส่งอีเมล์คือ mail() แต่ติดปัญหาคือเมล์ที่ส่งไปนั้นไม่ได้รับเนื่องจากอีเมล์ฉบับนั้นอยู่ใน Junkmail จึงทำให้รับความลำบากในการแก้ไขปัญหา ดังนั้น การใช้งาน PHPMailer จึงเป็นทางเลือกหนึ่ง...</p>
<p>The post <a href="https://www.itoffside.com/how-to-use-phpmailer-gmail-smtp/">การส่งอีเมล์ด้วย PHPMailer (โดยส่งผ่านอีเมล์ Gmail SMTP)</a> first appeared on <a href="https://www.itoffside.com">itOffside.com | บทความการเขียนโปรแกรม เรื่องราวข้อมูลเทคโนโลยี</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>PHPMailer เป็น Class ที่ถูกพัฒนาขึ้นในการส่งอีเมล์ เพื่อความสะดวกสบายในการเรียกใช้งานซึ่งโดยปกติทาง PHP มีฟังก์ชั่นการส่งอีเมล์คือ mail() แต่ติดปัญหาคือเมล์ที่ส่งไปนั้นไม่ได้รับเนื่องจากอีเมล์ฉบับนั้นอยู่ใน Junkmail จึงทำให้รับความลำบากในการแก้ไขปัญหา ดังนั้น การใช้งาน PHPMailer จึงเป็นทางเลือกหนึ่งในการแก้ไขปัญหาและ อีกทั้ง PHPMailer สามารถใช้งานได้ง่ายหากให้ gmail.com ในการส่งอีเมล์ โดยตัวอย่างบทความใช้ gmail SMTP<span id="more-2435"></span></p>
<p>สำหรับ PHPMailer คุณสามารถดาวน์โหลดได้ที่ <a title="PHPMailer" href="https://github.com/PHPMailer/PHPMailer/archive/master.zip">คลิกที่นี้เพื่อดาวน์โหลด</a><br />
เว็บหลักของ PHPMailer <a href="https://github.com/PHPMailer/">https://github.com/PHPMailer/</a></p>
<p><span style="text-decoration: underline;"><span style="color: #ff00ff; text-decoration: underline;"><strong>การติดตั้ง</strong></span></span><br />
1. หลังจากดาวน์โหลดมาแล้วให้ทำการแตกไฟล์ออกจะได้โฟล์เดอร์ PHPMailer<br />
2. Copy โฟล์เดอร์ PHPMailer มาไว้ในโปรเจคของคุณ</p>
<p><span style="text-decoration: underline;"><span style="color: #ff00ff; text-decoration: underline;"><strong>การใช้งาน</strong></span></span><br />
1. สร้างไฟล์ขึ้นมาหนึ่งไฟล์เพื่อทำการส่งอีเมล์ในตัวอย่างนี้สร้างไฟล์ชื่อ send.php แล้วให้คุณนำ code ที่ผมเขียนไปวางใส่</p><pre class="crayon-plain-tag">&lt;?php
/**
 * This example shows making an SMTP connection with authentication.
 */

//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Asia/Bangkok');

require 'PHPMailer/PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail-&gt;isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail-&gt;SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail-&gt;Debugoutput = 'html';
//Set the hostname of the mail server
$mail-&gt;Host = "smtp.gmail.com";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail-&gt;Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail-&gt;SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail-&gt;SMTPAuth = true;
//Username to use for SMTP authentication
$mail-&gt;Username = "your@gmail.com";
//Password to use for SMTP authentication
$mail-&gt;Password = "yourpassword";
//Set who the message is to be sent from
$mail-&gt;setFrom('your@gmail.com', 'Tony jone');
//Set who the message is to be sent to
$mail-&gt;addAddress('test@itoffside.com', 'itoffside');
//Set the subject line
$mail-&gt;Subject = 'itOffside.com test email';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
//$mail-&gt;msgHTML(file_get_contents('content.html'), dirname(__FILE__));
$mail-&gt;msgHTML("Test email by itoffside.com");

//send the message, check for errors
if (!$mail-&gt;send()) {
    echo "Mailer Error: " . $mail-&gt;ErrorInfo;
} else {
    echo "Message sent!";
}</pre><p>ความหมายแต่ละฟังก์ชั่นการทำการที่สำคัญ</p><pre class="crayon-plain-tag">require 'PHPMailer/PHPMailerAutoload.php';</pre><p>ทำการเรียกหาไฟล์ PHPMailerAutoload.php เพื่อใช้ฟังก์ชั่นส่งอีเมล์<br />
$mail-&gt;SMTPDebug = 0; <span style="color: #333399;">คือต้องการ debug หรือไม่หากไม่ใส่ 0</span><br />
$mail-&gt;Host = &#8220;smtp.gmail.com&#8221;; <span style="color: #333399;">คือ ค่า smtp ที่คุณจะต้องใส่หากส่งโดย gmail ให้ใส่ตามตัวอย่างส่วน hotmail ผมยังไม่ได้ทดสอบ</span><br />
$mail-&gt;Port = 587;<span style="color: #333399;"> คือ เลขพอร์ทของอีเมล์ หากส่งโดย gmail ให้ใส่ตามตัวอย่าง</span><br />
$mail-&gt;Username = &#8220;yourmail@gmail.com&#8221;;? <span style="color: #333399;">ชื่ออีเมล์ที่จะส่ง(แนะนำให้ใช้ gmail)</span><br />
$mail-&gt;Password = &#8220;yourpassword&#8221;; <span style="color: #333399;">รหัสผ่านที่ใช้ในการเข้าอีเมล์ของคุณ</span><br />
$mail-&gt;setFrom(&#8216;tangeaim.ball@gmail.com&#8217;, &#8216;Tony jone&#8217;); <span style="color: #333399;">ใส่ชื่ออีเมล์คุณและชื่อ นามสกุลคุณตามตัวอย่าง</span><br />
$mail-&gt;addAddress(&#8216;xxxxxxx@hotmail.com&#8217;, &#8216;itoffside&#8217;); <span style="color: #333399;">ใส่ชื่ออีเมล์ที่รับและชื่อ นามสกุลของคนที่รับอีเมล์</span><br />
$mail-&gt;Subject = &#8216;itOffside.com test email&#8217;;<span style="color: #333399;"> ชื่อเรื่องของอีเมล์</span><br />
$mail-&gt;msgHTML(&#8220;Test email by itoffside.com&#8221;); <span style="color: #333399;">ข้อความอีเมล์</span><br />
<span style="text-decoration: underline;"><span style="color: #ff0000; text-decoration: underline;">*หมายเหตุหากต้องการข้อความที่เป็น html ให้เปลี่ยนเป็นดังนี้ $mail-&gt;msgHTML(file_get_contents(&#8216;content.html&#8217;), dirname(__FILE__));</span></span></p>
<p>//send the message, check for errors<br />
if (!$mail-&gt;send()) {<br />
echo &#8220;Mailer Error: &#8221; . $mail-&gt;ErrorInfo;<br />
} else {<br />
echo &#8220;Message sent!&#8221;;<br />
}<br />
แสดงผลการส่งอีเมล์ (หากส่งสำเร็จส่งข้อความ Message sent!)<br />
<span style="color: #ff00ff;"><strong>ผลลัพธ์</strong></span><br />
<img decoding="async" class="alignnone size-full wp-image-2437" src="https://www.itoffside.com/wp-content/uploads/2015/01/011.jpg" alt="PHPMailer" width="334" height="119" srcset="https://www.itoffside.com/wp-content/uploads/2015/01/011.jpg 334w, https://www.itoffside.com/wp-content/uploads/2015/01/011-300x107.jpg 300w" sizes="(max-width: 334px) 100vw, 334px" /></p>
<p>ได้รับอีเมล์ที่ส่งมาจาก code PHPMailer<br />
<img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-2438" src="https://www.itoffside.com/wp-content/uploads/2015/01/021.jpg" alt="PHPMailer" width="397" height="269" srcset="https://www.itoffside.com/wp-content/uploads/2015/01/021.jpg 397w, https://www.itoffside.com/wp-content/uploads/2015/01/021-300x203.jpg 300w" sizes="(max-width: 397px) 100vw, 397px" /></p>
<p>สำหรับบทความนี้ก็จบแล้ว การใช้งาน PHPMailer นั้นใช้งานง่ายมีฟังก์ชั่นในการใช้งานมาให้แล้วเพียงแต่คุณต้องนำค่ามาใส่ให้ถูกต้องเท่านั้นและในตัวอย่างบทความนี้ เป็นการใช้งานพื้นฐานซึ่ง PHPMailer มีความสามารถมากมายให้ผู้ใช้งานได้ทดสอบ เช่น การส่งอีเมล์แนบไฟล์รูป เป็นต้น หวังว่าผู้อ่านทุกคนคงได้รับประโยชน์ไม่มากก็น้อยครับ หากมีคำถามให้เขียน comment ด้านล่างได้เลยครับ หากชอบก็กดแชร์และกด Like ได้ครับ ขอบคุณครับ</p><p>The post <a href="https://www.itoffside.com/how-to-use-phpmailer-gmail-smtp/">การส่งอีเมล์ด้วย PHPMailer (โดยส่งผ่านอีเมล์ Gmail SMTP)</a> first appeared on <a href="https://www.itoffside.com">itOffside.com | บทความการเขียนโปรแกรม เรื่องราวข้อมูลเทคโนโลยี</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.itoffside.com/how-to-use-phpmailer-gmail-smtp/feed/</wfw:commentRss>
			<slash:comments>26</slash:comments>
		
		
			</item>
	</channel>
</rss>
