Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Here is a working example:</strong></p> <pre><code>&lt;?php function SendMail( $ToEmail, $MessageHTML, $MessageTEXT ) { require_once ( 'class.phpmailer.php' ); // Add the path as appropriate $Mail = new PHPMailer(); $Mail-&gt;IsSMTP(); // Use SMTP $Mail-&gt;Host = "smtp.gmail.com"; // Sets SMTP server $Mail-&gt;SMTPDebug = 2; // 2 to enable SMTP debug information $Mail-&gt;SMTPAuth = TRUE; // enable SMTP authentication $Mail-&gt;SMTPSecure = "tls"; //Secure conection $Mail-&gt;Port = 587; // set the SMTP port $Mail-&gt;Username = 'MyGmail@gmail.com'; // SMTP account username $Mail-&gt;Password = 'MyGmailPassword'; // SMTP account password $Mail-&gt;Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low) $Mail-&gt;CharSet = 'UTF-8'; $Mail-&gt;Encoding = '8bit'; $Mail-&gt;Subject = 'Test Email Using Gmail'; $Mail-&gt;ContentType = 'text/html; charset=utf-8\r\n'; $Mail-&gt;From = 'MyGmail@gmail.com'; $Mail-&gt;FromName = 'GMail Test'; $Mail-&gt;WordWrap = 900; // RFC 2822 Compliant for Max 998 characters per line $Mail-&gt;AddAddress( $ToEmail ); // To: $Mail-&gt;isHTML( TRUE ); $Mail-&gt;Body = $MessageHTML; $Mail-&gt;AltBody = $MessageTEXT; $Mail-&gt;Send(); $Mail-&gt;SmtpClose(); if ( $Mail-&gt;IsError() ) { // ADDED - This error checking was missing return FALSE; } else { return TRUE; } } $ToEmail = 'Name@example.com'; $ToName = 'Name'; $Send = SendMail( $ToEmail, $MessageHTML, $MessageTEXT ); if ( $Send ) { echo "&lt;h2&gt; Sent OK&lt;/h2&gt;"; } else { echo "&lt;h2&gt; ERROR&lt;/h2&gt;"; } die; ?&gt; </code></pre> <p>I tried this script and had no problem sending several messages.</p> <p><strong>UPDATED:</strong></p> <p>This is the typical response from Gmail on success:</p> <pre><code>SMTP -&gt; FROM SERVER:220 mx.google.com ESMTP 20sm6345523qek.6 SMTP -&gt; FROM SERVER: 250-mx.google.com at your service, [181.155.13.39] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250 ENHANCEDSTATUSCODES SMTP -&gt; FROM SERVER:220 2.0.0 Ready to start TLS SMTP -&gt; FROM SERVER: 250-mx.google.com at your service, [181.155.13.39] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 250 ENHANCEDSTATUSCODES SMTP -&gt; FROM SERVER:250 2.1.0 OK 20sm6345523qek.6 SMTP -&gt; FROM SERVER:250 2.1.5 OK 20sm6345523qek.6 SMTP -&gt; FROM SERVER:354 Go ahead 20sm6345523qek.6 SMTP -&gt; FROM SERVER:250 2.0.0 OK 1353474062 20sm6345523qek.6 SMTP -&gt; FROM SERVER:221 2.0.0 closing connection 20sm6345523qek.6 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload