Knowledge Base/Help from the Community/Community Help

Using SendGrid as an email delivery system with PHPList

Steve Davies
posted this on August 02, 2011 11:05

I am *trying* to integrate SendGrid into an existing system to take over the bulk-delivery of newsletter emails.  We have our own SMTP server, but I'm switching to SendGrid (just for bulk emails) to enhance deliverability.  We use PHPList on the front end to run the email campaigns and intend tto use SendGrid API to connect it as the SMTP server.

 

Following the instructions on my account Developer dashboard I took the following;

SMTP server:  smtp.sendgrid.net
Username:  MyUsername on SendGrid
Password: MyPassword on SendGrid

I've seen conflicting instructions (on the SendGrid blog) advising that the username should be something along the lines 'mail.account@yourdomain.com' which I presume correlates the email address used in my Account Settings and where 'yourdomain' is the domain where the SMTP relay is applied.

None of these work.  PHPList shows the following error message, 'The following From address failed: xxxxxx@yourdomain.com'

Within config.php file (of PHPList) I have the following settings;

define("PHPMAILERHOST",'smtp.sendgrid.net');
$phpmailer_smtpuser = 'xxxxxx@yourdomain.com';
$phpmailer_smtppassword = 'MyPassword on SendGrid';
define('PHPMAILERPORT',25);

Can someone please resolve the conflicting advice about what to use for $phpmailer_smtpuser?  And are there any troubleshooting guides that I can use to resolve this and get SendGrid working with PHPList. 

Note: If I run PHPList through my own mail server then the test emails are delivered fine.
 

Comments

User photo
Steve Davies

Here's the solution for anyone else who experiences a similar issue with integrating PHPList and SendGrid:

1.  In File:  /lists/config/config.php at around line 670 REPLACE the code at this point with the following;

define ("TEST",0);
define("PHPMAILERHOST",'smtp.sendgrid.net');
$phpmailer_smtpuser = '<include your SendGrid account username>';
$phpmailer_smtppassword = '<include your SendGrid account password>';
$phpmailer_smtpsecure = 'ssl'; //ssl or tls or blank
$phpmailer_smtpport = '465';

 

2. In File:  /lists/admin/class.phplistmailer.php at around line 60..

REPLACE:

        $this->Helo = getConfig("website");
        $this->Host = PHPMAILERHOST;
        if ( isset($GLOBALS['phpmailer_smtpuser']) && $GLOBALS['phpmailer_smtpuser'] != ''
             && isset($GLOBALS['phpmailer_smtppassword']) && $GLOBALS['phpmailer_smtppassword']) {

          add $this->SMTPAuth = true;

          $this->Username = $GLOBALS['phpmailer_smtpuser'];
          $this->Password = $GLOBALS['phpmailer_smtppassword'];
        }

WITH:

        $this->SMTPAuth = true;
        //$this->Helo = getConfig("website");
        $this->Host = PHPMAILERHOST;
        
        $this->Username = $GLOBALS['phpmailer_smtpuser'];
        $this->Password = $GLOBALS['phpmailer_smtppassword'];
        $this->SMTPSecure = $GLOBALS['phpmailer_smtpsecure'];
        $this->Port = $GLOBALS['phpmailer_smtpport'];

 

3.  In File:  /lists/admin/phpmailer/class.smtp.php at around line 105..

REPLACE:

$this->smtp_conn = fsockopen($host, # the host of the server  

WITH:

$this->smtp_conn = fsockopen($host='ssl://smtp.sendgrid.net',

August 02, 2011 15:24
User photo
Joe Torma

Thank you.  This worked well, although the line numbers are way off in the current version.  Great work running this down.

August 05, 2012 23:59
User photo
Nic

Ok, is it work to send using Sendgrid Email Credits or Sendgrid Newsletter Credits?

October 16, 2012 16:57
User photo
Tim

I was wondering it anyone was able to get PHPList to work with SMTPAPI? Basically instead of sending 1 email at a time (uses heaps of server resources) with SMTP use SMTPAPI to send to 1000 email blocks. Basically instead of send 1 email a thousand times send it once so similar to BCC a thousand emails.

 

Nic: This uses Sendgrid Email Credits.

 

January 15, 2013 12:51
User photo
Adam

Hi all

I've tried using the above settings but i am having no luck. Is anyone using 1and1 hosting, not sure if its a block on their ports. If the connection fails does phplist revert back to hosted smtp?

February 15, 2013 08:06
User photo
Tim

Hi Adam,

Did you follow Steve Davies comment or the original post. The comment method worked for me. If you are doing that try other ports besides 465. The list is at http://sendgrid.com/docs/User_Guide/smtp_ports.html  . have to change $phpmailer_smtpsecure = 'ssl'; to $phpmailer_smtpsecure = 'tls';


Cheers

Tim

<a href="http://www.biostim.com.au/">BioStim</a>

February 15, 2013 14:55
User photo
Adam

Hi Tim

thanks for your reply

I found out that 1and1 wouldnt allow outgoing smtp connections and they have blocked 25,487 and so on.

I've not moved the hosting to just host as they do allow the connection but i still cant get it to work. The emails still show in the header they are coming from the hosting company. I've changed the settings but there must still be something telling phplist to use the host smtp!

If connection fails to external smtp does the host smtp takeover?

thanks

February 15, 2013 15:31
User photo
Tim

You are right if it breaks out of the above code (external smtp) it will use local server. The above works on Hostgator but they have limits on size of list and sending speed. 

Options I can see is try to change the above to use the Sendgrid Web API to get around the blocked ports. I am trying to get SMTP API to work without much luck as it breaks out to uses server smtp. 

Upgrade to higher level and use Sendgrids Newsletter app so you can drop PHPlist totally. Not practical for me as I don't send that many emails. 

February 15, 2013 15:49