Avatar of jebbie635
jebbie635
 asked on

SMTP Headers for PHP Mailer

Hi experts,

I need full smtp headers for a php mailer. This is what i have and its not working.

$connect = fsockopen($hostname,$port); 
fputs($connect, "EHLO $mydomain\r\n"); 
fputs($connect, "AUTH LOGIN\r\n"); 
fputs($connect, base64_encode($username)."\r\n"); 
fputs($connect, base64_encode($password)."\r\n"); 
fputs($connect, "FROM:$fromname <$fromemail>\r\nReply-To: $replyto\r\n");
fputs($connect, "RCPT TO:$fullname <$email>\r\n"); 
fputs($connect, "DATA\r\n"); 
fputs($connect, "MIME-Version: 1.0\r\n");
fputs($connect, "Content-Type: text/html\r\n");
fputs($connect, "Content-Transfer-Encoding: base64\r\n\r\n");
fputs($connect, "To: $email\n");
fputs($connect, "Subject: $subject\n\n"); 
fputs($connect, "$message\r\n"); 
fputs($connect, ".\r\n"); 
fputs($connect, "QUIT\r\n");

Open in new window


Thanks,
PHPEmail Servers

Avatar of undefined
Last Comment
Barthax

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Barthax

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Barthax

Note also that your lines of the e-mail should all end in \r\n and so after the Subject line you should have \r\n\r\n to provide the blank line between the headers and the message body.

SMTP standard: http://tools.ietf.org/html/rfc2821
E-mail format: http://tools.ietf.org/html/rfc2822

$connect = fsockopen($hostname,$port); 
fputs($connect, "EHLO $mydomain\r\n"); 
fputs($connect, "AUTH LOGIN\r\n"); 
fputs($connect, base64_encode($username)."\r\n"); 
fputs($connect, base64_encode($password)."\r\n"); 
fputs($connect, "MAIL FROM: \"$fromname\" <$fromemail>\r\n");
fputs($connect, "RCPT TO:$fullname <$email>\r\n"); 
fputs($connect, "DATA\r\n"); 
fputs($connect, "MIME-Version: 1.0\r\n");
fputs($connect, "Content-Type: text/html\r\n");
fputs($connect, "Content-Transfer-Encoding: base64\r\n");
fputs($connect, "To: $email\r\n");
fputs($connect, "From: "$fromname" <$fromemail>\r\nReply-To: $replyto\r\n");
fputs($connect, "Subject: $subject\r\n\r\n"); 
fputs($connect, "$message\r\n"); 
fputs($connect, ".\r\n"); 
fputs($connect, "QUIT\r\n");

Open in new window


(Corrected headers in e-mail.)
Ray Paseur

Have you considered using the free and open-source PHPMailer class?  It might be easier.  Just a thought...
https://code.google.com/a/apache-extras.org/p/phpmailer/

And if you find that you're still wrestling with email anomalies and edge cases (as most of us do) you might want to consider a professionally hosted service.  This one has worked well for me.
http://search.constantcontact.com/index.jsp
jebbie635

ASKER
Is 'TO' required ? Isnt the same with 'RCPT-TO' ?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Barthax

There are two parts to sending an e-mail: the SMTP protocol in which RCPT TO is required and the e-mail itself in which the To: header is sent.  The e-mail itself is sent in the SMTP DATA command.  Everything here constitutes what the the e-mail client sees:
fputs($connect, "MIME-Version: 1.0\r\n");
fputs($connect, "Content-Type: text/html\r\n");
fputs($connect, "Content-Transfer-Encoding: base64\r\n");
fputs($connect, "To: $email\r\n");
fputs($connect, "From: "$fromname" <$fromemail>\r\nReply-To: $replyto\r\n");
fputs($connect, "Subject: $subject\r\n\r\n"); 
fputs($connect, "$message\r\n"); 
fputs($connect, ".\r\n"); 

Open in new window


... and also what the SMTP server essentially ignores. :)
jebbie635

ASKER
Omg this is so much reading and cant understand it. Please correct the code, this shouldnt be much for you. I really need it. This is the mailer here:

<?php
error_reporting(E_ALL); 

// MESSAGE DETAILS

$fromemail   = "";
$fromname    = "";
$replyto     = "";
$subject     = "";
$fullname    = "";
$email       = "";
$message     = "";

// SMTP INFO

$hostname    = "";
$username    = "";
$password    = "";
$port        = 25;
$mydomain    = "";

// SMTP CONNECT

$connect = fsockopen($hostname,$port); 
fputs($connect, "EHLO \'$mydomain\'\r\n"); 
fputs($connect, "AUTH LOGIN\r\n"); 
fputs($connect, base64_encode($username)."\r\n"); 
fputs($connect, base64_encode($password)."\r\n"); 
fputs($connect, "MAIL FROM: \'$fromname\' <$fromemail>\r\n");
fputs($connect, "RCPT TO: \'$fullname\' <$email>\r\n"); 
fputs($connect, "DATA\r\n"); 
fputs($connect, "MIME-Version: 1.0\r\n");
fputs($connect, "Content-Type: text/html\r\n");
fputs($connect, "Content-Transfer-Encoding: base64\r\n");
fputs($connect, "To: \'$email\'\r\n");
fputs($connect, "From: \'$fromname\' <$fromemail>\r\nReply-To: $replyto\r\n");
fputs($connect, "Subject: \'$subject\'\r\n\r\n"); 
fputs($connect, "\'$message\'\r\n"); 
fputs($connect, ".\r\n"); 
fputs($connect, "QUIT\r\n"); 

?>

Open in new window

SOLUTION
Barthax

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
jebbie635

ASKER
Its not sending. What is wrong?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
jebbie635

ASKER
I tried telnet and the server is working with this headers, so this code sends data wrong. Anybody?
jebbie635

ASKER
Thanks.

This is working:

<?php
error_reporting(E_ALL);

// MESSAGE DETAILS

$email       = "";
$fromemail   = "";
$fromname    = "";
$replyto     = "";
$subject     = "";
$message     = "";
$mydomain    = "";

// SMTP INFO

$hostname    = "";
$username    = "";
$password    = "";

// SMTP CONNECT

$connect = fsockopen($hostname, 25);
fputs($connect, "EHLO $mydomain\r\n");
fputs($connect, "AUTH LOGIN\r\n");
fputs($connect, base64_encode($username)."\r\n");
fputs($connect, base64_encode($password)."\r\n");
fputs($connect, "MAIL FROM: $fromemail\r\n");
fputs($connect, "RCPT TO: $email\r\n");
fputs($connect, "DATA\r\n");
fputs($connect, "MIME-Version: 1.0\r\n");
fputs($connect, "Content-Type: text/html\r\n");
fputs($connect, "Content-Transfer-Encoding: 8bit\r\n");
fputs($connect, "To: \"$fullname\" <$email>\r\n");
fputs($connect, "From: \"$fromname\" <$fromemail>\r\n");
fputs($connect, "Reply-To: $replyto\r\n");
fputs($connect, "Subject: $subject\r\n\r\n");
fputs($connect, "$message\r\n");
fputs($connect, ".\r\n");
fputs($connect, "QUIT\r\n");

?>
Barthax

Glad you got there in the end. :)
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck