This post about "Sending Mail using SMTP and PHP". Now you can send emails with SMTP authentication using this script. Every mail needed server authentication, So you have to buy mail server. It's very useful you can implement this on your web projects.
- Index.php
- SMTPconfig.php // SMTP Server Cofiguration
- SMTPClass.php // SMTP Mail Sending Class
Updated: Send mail using Gmail SMTP using PHP
SMTPconfig.php
You have to change SMTP server details.
<?php
//Server Address
$SmtpServer="127.0.0.1";$SmtpPort="25"; //default
$SmtpUser="username";
$SmtpPass="password";
?>
SMTPclass.php
SMTP mail sending class.
<?php
class SMTPClient{
function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body)
{
$this->SmtpServer = $SmtpServer;
$this->SmtpUser = base64_encode ($SmtpUser);
$this->SmtpPass = base64_encode ($SmtpPass);
$this->from = $from;
$this->to = $to;
$this->subject = $subject;
$this->body = $body;
if ($SmtpPort == "")
{
$this->PortSMTP = 25;
}
else
{$this->PortSMTP = $SmtpPort;
}
}
function SendMail ()
{
if ($SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP))
{
fputs ($SMTPIN, "EHLO ".$HTTP_HOST."\r\n");
$talk["hello"] = fgets ( $SMTPIN, 1024 );
fputs($SMTPIN, "auth login\r\n");
$talk["res"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpUser."\r\n");
$talk["user"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpPass."\r\n");
$talk["pass"]=fgets($SMTPIN,256);
fputs ($SMTPIN, "MAIL FROM: <".$this->from.">\r\n");
$talk["From"] = fgets ( $SMTPIN, 1024 );
fputs ($SMTPIN, "RCPT TO: <".$this->to.">\r\n");
$talk["To"] = fgets ($SMTPIN, 1024);
fputs($SMTPIN, "DATA\r\n");
$talk["data"]=fgets( $SMTPIN,1024 );
fputs($SMTPIN, "To: <".$this->to.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n\r\n\r\n".$this->body."\r\n.\r\n");
$talk["send"]=fgets($SMTPIN,256);
//CLOSE CONNECTION AND EXIT ...
fputs ($SMTPIN, "QUIT\r\n");
fclose($SMTPIN);
//
} return $talk;
}
}
?>
index.php
<?php
include('SMTPconfig.php');include('SMTPClass.php');
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$to = $_POST['to'];
$from = $_POST['from'];
$subject = $_POST['sub'];
$body = $_POST['message'];
$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
$SMTPChat = $SMTPMail->SendMail();
}
?>
<form method="post" action="">
To:<input type="text" name="to" />From :<input type='text' name="from" />
Subject :<input type='text' name="sub" />
Message :<textarea name="message"></textarea>
<input type="submit" value=" Send " />
</form>
Latest 20 Articles
Thanks. Very useful.
ReplyDeletenice useful
DeleteNice coding...
ReplyDeletea piece of great code, thanks.
ReplyDeleteby the way, is there method to default the coding of the email as unicode(UTF8)?
how can i add cc: ???
ReplyDeletedoes this work for gmail smtp servers?
ReplyDelete@beezy
ReplyDeleteNo
You need to use unsecure mail servers that use port 25. Check your IP for details (if you have an email account with them, look under SMTP configuration for Outlook, Thunderbird, etc)
ReplyDeletedoes it work for aol smtp server?
ReplyDeleteNotice: Undefined variable: HTTP_HOST in C:\wamp\www\1010\SMTPclass.php on line 30
ReplyDeleteThanks,
ReplyDeleteI really search for this script form last 1 week & i fount this script work fine for me.
Thanks again.
Thank you very much for this useful class, how can we use it to send HTML emails?
ReplyDelete@gustavo
It's possible to add cc.
1- You need to change first you index.php:
You've got to add a new field called cc in your form. Then recover it to $cc from POST Array (within the other variables as $from, $to ...). Finally, you must add $cc between $to and $subject in the SMTPClient function call.
2- Then you go to change SMTPClass.php:
You must add $cc to SMTPClient function definition the same way you did in the function call. THen add a new variable called $this->cc where you put the actual $cc.
Duplicate the RCPT TO command using your new variable $this->cc and get the response in the $talk[...] array:
fputs ($SMTPIN, "RCPT TO: <".$this->cc.">\r\n");
$talk["Cc"] = fgets ($SMTPIN, 1024);
Finally, put your variable on the mail header, by adding the following line right after its "To:" similar line under DATA command:
Cc: <".$this->cc.">\r\n
The final DATA command is:
fputs($SMTPIN, "DATA\r\n");
$talk["data"]=fgets( $SMTPIN,1024 );
fputs($SMTPIN, "To: <".$this->to.">\r\nCc: <".$this->cc.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n\r\n\r\n".$this->body."\r\n.\r\n");
$talk["send"]=fgets($SMTPIN,256);
That's it! You can do it the same way with BCc too...
i'm getting this error:
ReplyDeleteNotice: Undefined variable: HTTP_HOST in /var/www/vhosts/cutrin.lt/httpdocs/evelita/mailtest/SMTPClass.php on line 30
Thanks youuuuuuuuuuu.....
ReplyDeletethis not support html mail
ReplyDeleteproblem when I send subject in arabic
ReplyDeleteHow i solve it?
Thankq very Much.
ReplyDeleteGod bless you
SMTPClass.php is not SMTPclass.php
ReplyDeleteYour script and include files names do not match,
Warning: fsockopen() [function.fsockopen]: unable to connect to smtp.gmail.com:25 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ) in D:\xampp\htdocs\NetBill Manager\admin\SMTPClass.php on line 28
ReplyDeleteFatal error: Maximum execution time of 60 seconds exceeded in D:\xampp\htdocs\NetBill Manager\admin\SMTPClass.php on line 28
please help me to include headers
ReplyDeleteEx: $headers = "Content-Transfer-Encoding: 8bit\r\n";
$headers .= 'Content-Type: text/html; charset="iso-8859-1"'."\r\n";
Thanks so much.
ReplyDeleteNotice: Undefined variable: HTTP_HOST in .../SMTPclass.php on line 30
ReplyDeleteWarning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\wamp\www\SMTPclass.php on line 31
ReplyDeleteWarning: fsockopen() [function.fsockopen]: unable to connect to 192.168.1.3 :25 (php_network_getaddresses: getaddrinfo failed: No such host is known. ) in C:\wamp\www\SMTPclass.php on line 31
i copied the three php programs and wen i try to run the index.php file it in d wamp server,
ReplyDeleteits gives d following error:
Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\wamp\www\SMTPclass.php on line 31
Warning: fsockopen() [function.fsockopen]: unable to connect to 192.168.1.3 :25 (php_network_getaddresses: getaddrinfo failed: No such host is known. ) in C:\wamp\www\SMTPclass.php on line 31
//i hav no clue wts wrong....m a newbie....i hav been tryn dis for a while but widout success....
Nice post..
ReplyDeleteYou can set header by this:
fputs($SMTPIN, "To: <".$this->to.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n".$this->headers."\r\n\r\n".$this->body."\r\n.\r\n");
And pass the header in constructor as an argument and than set that like:
$this->headers = $headers;
And that's all !!!
Reza Said:
ReplyDeletehow can I send email to more than one person on one textbox ?
Thanks Srinivas for this nice post. I reformatted your SMTPClient class and added a header variable so one has the option to send HTML emails.
ReplyDeleteSmtpServer = $SmtpServer;
$this->SmtpUser = base64_encode ($SmtpUser);
$this->SmtpPass = base64_encode ($SmtpPass);
$this->from = $from;
$this->to = $to;
$this->subject = $subject;
$this->body = $body;
$this->newLine = "\r\n";
if ($SmtpPort == "") {
$this->PortSMTP = 25;
} else {
$this->PortSMTP = $SmtpPort;
}
}
function SendMail (){
if ($SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP)) {
fputs ($SMTPIN, "EHLO ".$HTTP_HOST."\r\n");
$talk["hello"] = fgets ( $SMTPIN, 1024 );
fputs($SMTPIN, "auth login\r\n");
$talk["res"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpUser."\r\n");
$talk["user"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpPass."\r\n");
$talk["pass"]=fgets($SMTPIN,256);
fputs ($SMTPIN, "MAIL FROM: <".$this->from.">\r\n");
$talk["From"] = fgets ( $SMTPIN, 1024 );
fputs ($SMTPIN, "RCPT TO: <".$this->to.">\r\n");
$talk["To"] = fgets ($SMTPIN, 1024);
fputs ($SMTPIN, "RCPT TO: \r\n");
$talk["Bcc"] = fgets ($SMTPIN, 1024);
fputs($SMTPIN, "DATA\r\n");
$talk["data"]=fgets( $SMTPIN,1024 );
//Construct Headers
$headers = "MIME-Version: 1.0" . $this->newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $this->newLine;
$headers .= "From: <".$this->from.">". $this->newLine;
$headers .= "To: <".$this->to.">". $this->newLine;
$headers .= "Bcc: newLine;
$headers .= "Subject: ".$this->subject. $this->newLine;
fputs($SMTPIN, $headers."\r\n\r\n".$this->body."\r\n.\r\n");
$talk["send"]=fgets($SMTPIN,256);
//CLOSE CONNECTION AND EXIT ...
fputs ($SMTPIN, "QUIT\r\n");
fclose($SMTPIN);
//
}
return $talk;
}
}
?>
Anyone know a way to make this code work with Gmail? Dont you just need to allow SSL somehow and use port 465 or 587?
ReplyDeleteMails are going to Spam box. can you help me resolve it.
ReplyDeleteI am getting this error please help me to solve
ReplyDeleteUndefined variable: HTTP_HOST in C:\wamp\www\smtp\SMTPclass.php on line 39
i agree
DeleteDoes this have any special server-end requirements to run? My host (DreamHost) is saying that SMTP like this requires PEAR and the fact that I can't get it to work seems to back that up. Not getting any errors like some users above, just no emails coming thru. Any thoughts?
ReplyDeleteheh.. I had this working last weekend.. I think my CPanel server either upgraded exim or something because this script is now sending out emails but when it hits the exim server im getting errors:
ReplyDelete2011-09-10 08:17:13 H=area (localhost) [127.0.0.1] rejected MAIL [email protected]: Authentication failed
Thoughts on that? I know its not the php issue, or is it? Running 5.3.8 of PHP
thnx for this class ,
ReplyDeletebut how can i get a confirmation message
if mail fails to b delivered then how can i get to know about that ??
Hi,
ReplyDeleteAll..It is best code which help me very bad time...Thanks you all guys..and for your valuable posting..
I have seen one post is no pending for help..
Undefined variable: HTTP_HOST in C:\wamp\www\smtp\SMTPclass.php
Who are waiting for the above error code help..
plz see the bellow
----------
Please replace the "$HTTP_HOST" to "$this->SmtpServer".
Then enjoy the fun with you..
judhisthira sahoo
India
Thank you
ReplyDeleteit is excellent .
But how to set server inside config file to send Email to yahoo ?
Nice job,
ReplyDeletethis code worked beautifully for me to connect to godaddys smtp
I have tried this and its working properly. Is it possible to add attachment when sending an email using smtp? Thanks. :)
ReplyDeletenice script. but can u plz help me out on the attachment issue?
ReplyDeleteto solve problem of "Undefined variable: HTTP_HOST"
ReplyDeletereplace it with "getenv('MyHost')", it worked well with me...
and i am reallly grateful for this post..thank you soooo much (^_^)
regarding the SMTPconfig.php... ca we put mail.domain.com at $SmtpServer? something like this:
ReplyDeleteany help?
The Bcc or Cc seem to work however the received email also shows who the Bcc/Cc is. For Bcc this is a problem b/c it's not BLIND. The following is what my hosting company said about this:
ReplyDelete"It looks as your script is adding the BCC header of the message. at the wrong place. We would recommend that you check the configuration of the script that you are using to send the message. "
Thanks a lot. You are the man!
ReplyDeletethe line
ReplyDelete$talk["hello"] = fgets ( $SMTPIN, 1024 );
Would be better as
$talk["hello"] = stream_get_line( $SMTPIN, 1024 );
as the server can return a multi line greeting which can still be returned in many of the following fget commands rather than getting what you would expect.
Very very thankful for your valuable post
ReplyDeleteThank you so much!! That's what i need.. very3 thank you...
ReplyDeleteI copy and paste code and make some change the script run successfully but email not received by client.
ReplyDeleteplease help
thank in ad..
Works like a charm thanks!
ReplyDeleteindex.php downloads instead of opening....
ReplyDelete@Elite Web Services: you have to open the file on a web server
ReplyDeleteHello. Nice class. How can i send mail to multiple users? i use such codes: fputs ($SMTPIN, "RCPT TO: , , \r\n");
ReplyDeleteBut it deliveres only to first mail, to mail-1.
I open delivered email in mail-1, and in TO section all mails are shown. To: you,mail-2,mail-3.
But mail-2 and mail-3 don't get email.
Hello,i used reformatted SMTPClient class,which is send HTML email, But my email not in HTML format and did not found content-type on message source. could anyone help ?
ReplyDeleteSorry, i did some mistaken on header. now already work in accordingly. Thank you !
ReplyDeleteSorry, i did some mistaken on header. now already work in accordingly. Thank you !
ReplyDeleteOkay, my solution for HTML and a Bcc which you could change to Cc easily.
ReplyDeleteindex.php
top of the page:
$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $bcc, $subject, $body, $headers);
You will also use this structure later on in index.php when calling the function.
SMTPClass.php
Replaces the function line
function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $bcc, $subject, $body, $headers)
Add this a few lines down under the rest of them
$this->headers = $headers;
$this->bcc = $bcc;
Add this below the same one call Data
fputs ($SMTPIN, "RCPT TO: <".$this->bcc.">\r\n");
$talk["Bcc"] = fgets ($SMTPIN, 1024);
Then replace this a few lines below:
fputs($SMTPIN, "To: <".$this->to.">\r\nBcc: <".$this->bcc.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n".$this->headers."\r\n\r\n".$this->body."\r\n.\r\n");
Then just set the variables up in the index.php with your values however you like
Alongside that, I forgot to mention in index.php you'll need to add this just before the function is called:
ReplyDelete$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
This will send it as HTML
Thanks alot it still pending when i send email to gmail !
ReplyDeleteproblem when I send subject in arabic
ReplyDeleteHow to solve it?
[data] => 500 Syntax error, command unrecognized [send] => 250 OK.
ReplyDeleteThis is what am getting in my array SMTPChat and cant understand why?
Warning: fsockopen() [function.fsockopen]: unable to connect to mail.bumaindonesia.com:25 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ) in C:\Program Files\xampp\htdocs\Email\SMTPclass.php on line 28
ReplyDeleteFatal error: Maximum execution time of 60 seconds exceeded in C:\Program Files\xampp\htdocs\Email\SMTPclass.php on line 28
Notice: Undefined variable: HTTP_HOST
ReplyDeleteThanks!
ReplyDeleteGreat PHP I love it.
ReplyDeletecanyou plase show us how to send a attachment like a picture orother file.
this make the cookies better.
best regards
Gil
How Can BCC part can be added to this and email can be sent group of people at once?
ReplyDeleteNotice: Undefined variable: HTTP_HOST in C:\xampp\htdocs\SMTPclass.php on line 30
ReplyDeleteFatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\SMTPclass.php on line 31 error
hi all i am getting an SMTP Error: Could not connect to SMTP host. my mail function is
ReplyDeletefunction sendMailSmtp($email, $meaasge, $subject, $attachment='') {
$mail = new PHPMailer();
$body = $meaasge;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.a3spl.com";
$mail->Port =25;
$mail->Username = "[email protected]";
$mail->Password = "xyzxyz";
$mail->From = "XYZ";
$mail->FromName = "XYZ";
$mail->Subject = $subject;
$mail->AltBody = "This is the body when user views in plain text format";
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($body);
if(trim($attachment) != ''){
$mail->AddAttachment("uploadUserData/download/".$attachment);
}
$mail->AddAddress($email, "First Last"winking smiley;
$mail->IsHTML(true);
if (!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
return FALSE;
} else {
return true;
}
}
plz help mee soon
Ok, after hours of struggling i have working solution with attachments...
ReplyDeleteHere we go (SMTPClass.php):
copy/paste this:
function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body, $filename)
{
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers = "MIME-Version: 1.0" . "\r\n"."Content-Type: multipart/mixed;" . "\r\n"." boundary=\"{$mime_boundary}\"";
$fileatt_name = "$filename"; // Filename that will be used for the file as the attachment
$fileatt_type = "application/octet-stream"; // File Type
$handle = fopen($fileatt_name,'rb');
$data = fread($handle,filesize($fileatt_name));
fclose($handle);
$data = chunk_split(base64_encode($data));
$body_with_att = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $body . "\n\n" . "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n";
Instead you current one and just before there "$this..." starts
change: "$this->body = $body;" to: "$this->body = $body_with_att;"
check that you have exact contents for this line:
fputs($SMTPIN, "To: <".$this->to.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n".$this->headers."\r\n\r\n".$this->body."\r\n.\r\n");
(index.php):
Copy/paste this instead of "$SMTPMail = new SMTPClient ...":
$filename = "mpsbox.tgz";
$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body, $filename);
remove any headers from index.php, if added one's for html support.
Good luck!
Hi ,
ReplyDeleteI`m getting 530 error .
Reason: Remote host said: 530 SMTP authentication is required.
i cannot send mail...please help..
ReplyDeletetried the sript.. changed the server setails etc.. but mail not received
Undefined variable: HTTP_HOST in C:\wamp\www\smtp\SMTPclass.php on line 39
ReplyDeleteWarning: fsockopen() [function.fsockopen]: unable to connect to 127.0.0.1:25 (No connection could be made because the target machine actively refused it. ) in C:\wamp\www\check\mail\SMTPmail\SMTPClass.php on line 35
ReplyDeleteCall Stack
# Time Memory Function Location
1 0.0012 369880 {main}( ) ..\Index.php:0
2 0.0022 395552 SMTPClient->SendMail( ) ..\Index.php:11
3 0.0022 395584 fsockopen ( ) ..\SMTPClass.php:35
( ! ) Notice: Undefined variable: talk in C:\wamp\www\check\mail\SMTPmail\SMTPClass.php on line 68
Call Stack
# Time Memory Function Location
1 0.0012 369880 {main}( ) ..\Index.php:0
2 0.0022 395552 SMTPClient->SendMail( ) ..\Index.php:11
To :
Hi guys. I am new to php coding and creating contact form for the first time.
ReplyDeleteI tried sending mail from my domain to gmail through above code but that didnt work for me.
I think i am confused because i actually dont know how people generally use contact form?
How contact form should work ideally..it should send email like [email protected] to which emailid? I am confused who will be sender and receiver here?
if ('SMTPconfig.php' == basename($_SERVER['SCRIPT_FILENAME']))
ReplyDeletedie ('Direct File Access Prohibited');
add above into head of SMTPconfig.php to prevent direct access.
Thanks for Srinivas for the nice article and code snippet. I did exactly what you have mentioned but i am not able to send mail using SMTP option.
ReplyDeleteDo i need to install any mail package?
VP
Hello Srinivas Tamada
ReplyDeleteFirst of all, thanks a lot for this great script!!
It works like a charm!!
I need to add something very simple, but really don't know how to do it since my strong is not php...
I need to perform an echo check to know if the email has been sent correctly or not, for example:
$to = $_POST['to'];
$from = $_POST['from'];
$subject = $_POST['sub'];
$body = $_POST['message'];
$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
$SMTPChat = $SMTPMail->SendMail();
}
if (SendMail)
{
echo "success";
}
else
{
echo "error";
}
I know this doesn't work...echos success always, but I need something like this...any ideas?
Thanks a lot in advance!!
Cheers!
Hi Diego,
ReplyDeleteAfter $SMTPChat = $SMTPMail->SendMail(); put something like:
$sent = true;
then instead of if(SendMail)use if($success == true) {
Thanks man, had this problem with cent os + mantis (new installation wich I didn't made). You helped me good !
ReplyDeleteThx !
i can connect smptp,but I can't receive the email I sent, why?
ReplyDeletewhats the problem?
unable to use ,getting warning as
ReplyDeleteWarning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in XXXXX
Please help.
but its not working for gmail smtp plz
ReplyDeletehelp me
gd coding but it is not working....so plz help me
ReplyDeletei can connect smptp,but I can't receive the email I sent, why?
ReplyDeletewhats the problem?
I am having the same problem as Zeihan Aulia:
ReplyDelete"i can connect smptp,but I can't receive the email I sent, why?
whats the problem?"
I have put debug code throughout and found that everything appears to execute successfully, but I never actually receive any emails. Any thoughts??
i am entered in textarea maximum 729 characters to enter button click success message and received the mail. but 730 or more than characters entered mail send but not received the mail. why this reason not send on mail. please help
ReplyDeleteFirst of all thanks for your nice codings. I used your emailing code and its working fine.
ReplyDeletePlease also help me how to mention FromName in the email coding.
currently if David Clark is mailing from [email protected] then FromName is comming as "david" But I want its name "David Clark".
so please help me.
Notice: Undefined variable: HTTP_HOST in E:\wamp\www\lastmail\SMTPClass.php on line 38
ReplyDeleteHello, very nice and useful. Thanks for the great script.
ReplyDelete1.How can i send mail to multiple users?
2.I am able to do CC or BCC.
3.I would like to add multiple users in TO: , not using cc or bcc.
Help me. thanks much
Hello,
ReplyDeleteAt the end of index.php I've added this: print_r($SMTPChat);
All I get is Array ( [hello] => [res] => [user] => [pass] => [From] => [To] => [data] => [send] => ) why is this happening?
Thanks ! Nice way to send mail
ReplyDelete-Anup
Very useful thx
ReplyDeleteNotice: Undefined variable: HTTP_HOST in C:\wamp\www\SMTPmail\SMTPClass.php
ReplyDeleteaidez moi svp
its still. I have tried your code for sending html. it is not sending as html email
ReplyDeleteHello!
ReplyDeleteI'm french and i want to sent mail with accent!
How can I do this?
Please help me!
Thank you!!
Please Help me! It is very urgent! TT_TT
ReplyDeletecan you post full code to send as HTML mail
ReplyDeleteI have found alone...^^
ReplyDeleteYou can had this code next to $this->subject\r\n : Content-Type: text/plain; charset={UTF-8}\r\n
So finnaly, it is (for example):
fputs($SMTPIN, "To: <".$this->to.">\r\nCc:<".$this->cc.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n"."Content-Type: text/plain; charset={UTF-8}\r\nComments :".$this->body."\r\n.\r\n");
So, enjoy it! And really thank you!!!
i'm getting this error:
ReplyDeleteWarning: fsockopen() [function.fsockopen]: unable to connect to 173.194.79.108:465 (Connection refused) in /home/content/61/4521261/html/SMTPmail/SMTPClass.php on line 35
please help me.
Hello! There is a fault!
ReplyDeleteYou must add this code: $this->subject\r\n : Content-Type: text/plain; charset=UTF-8\r\n
(There is no accolade, i don't know if you understand...)
So finally, it is:
fputs($SMTPIN, "To: <".$this->to.">\r\nCc:<".$this->cc.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n"."Content-Type: text/plain; charset=UTF-8\r\nComments :".$this->body."\r\n.\r\n");
So it's all, I think!! Bye!!
Very nice script.
ReplyDelete
ReplyDeleteFatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\test\SMTPmail\SMTPClass.php on line 39
Error :Notice: Undefined variable: HTTP_HOST in C:\xampp\htdocs\SMTPclass.php on line 30
ReplyDeleteplzz help
i tried this. nothing happens..
ReplyDeleteFor the Error:
ReplyDeleteError :Notice: Undefined variable: HTTP_HOST in
Please change:
fputs ($SMTPIN, "EHLO ".HTTP_HOST."\r\n");
for
fputs ($SMTPIN, "EHLO ".$_SERVER["HTTP_HOST"]."\r\n");
I cannot seem to get my SMTPworking on a server it only works when I am using a local host, how do I configure it to work on any server that I can upload my php files ?
ReplyDeleteHere is my working script
Very nice script.
ReplyDeleteWhen I receive the email the from field is [email protected] how can I change this to use an alias like php mail() headers. eg. From: Gordon .
Also the sent field in the email received says none instead of the date?
Please can anyone help?
Mr.admin im getting this error..
ReplyDeleteWarning: fsockopen() [function.fsockopen]: unable to connect to 127.0.0.1:25 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ) in C:\wamp\www\SMTPmail\SMTPClass.php on line 35
Notice: Undefined variable: talk in C:\wamp\www\SMTPmail\SMTPClass.php on line 68
please help me...
Script is working Fine..
ReplyDeleteHow to change body of the content html template?
Warning: fsockopen() [function.fsockopen]: unable to connect to 127.0.0.1:25 (No connection could be made because the target machine actively refused it. ) in C:\wamp\www\check\mail\SMTPmail\SMTPClass.php on line 35
ReplyDeletei got this error on smtp mail
plz any one send the correct smtp mail code on my mail
[email protected]
plzzzzzzzzzzzzzzz help me
really really TY man!!!!!!!!!
ReplyDeletereally really TY man!!!!!!! seriously
ReplyDeleteThumbs up!
ReplyDeletefrom where to buy SMTP server Can we get free
ReplyDeletedata are not specified using the SMTP server, or you need to edit something for which SMTP server to use
ReplyDeleteThanks a lot
ReplyDeleteIts working perfectly. Thank you
ReplyDeleteNow i just need to try the code for attachments
ReplyDelete( ! ) Notice: Undefined variable: HTTP_HOST in C:\wamp\www\smtp
i am new to the php.. i am using same code but below error is coming so what to do.....
mail\SMTPClass.php on line 38
Call Stack
# Time Memory Function Location
1 0.0010 144576 {main}( ) ..\Index.php:0
2 0.0130 157920 SMTPClient->SendMail( ) ..\Index.php:11
can i send email on yahoo or gmail using this script
ReplyDeleteHi... plz someone help for secured SSL email using gmail SMTP.
ReplyDeletefsockopen(): unable to connect to 127.0.0.1:25 (No connection could be made because the target machine actively refused it. ) in C:\xampp\htdocs\mail\SMTPClass.php on line 35 why this warning is coming
ReplyDeleteMail showing html tags, what is the error???
ReplyDeleteI have a problem
ReplyDeleteWhen input user & password is error.
How get error info & send success or fail
Hello Experts I am fresher in php. I need your help. Please guide me.
ReplyDeleteI m using same script for sending form mail but getting below error.
Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: No such host is known. in E:\inetpub\vhosts\leminarindustries.com\httpdocs\formsend\SMTPClass.php on line 30
Warning: fsockopen() [function.fsockopen]: unable to connect to smpt.gmail.com:465 (php_network_getaddresses: getaddrinfo failed: No such host is known. ) in E:\inetpub\vhosts\leminarindustries.com\httpdocs\formsend\SMTPClass.php on line 30
How can we use recaptcha with this script?
ReplyDeletehow can to at a time all user send mail script
ReplyDeleteThanks a lot
ReplyDeletePHP Fatal error: Class 'SMTPClient' not found in /home/banlabco/public_html/SMTP/index.php on line 10
ReplyDeletesend two mail different email id on my smtp sendmail function
ReplyDeleteWarning: fsockopen(): unable to connect to 127.0.0.1:25 (No connection could be made because the target machine actively refused it. ) in C:\xampp\htdocs\SMTPmail (1)\SMTPClass.php on line 35
ReplyDeleteNotice: Undefined variable: talk in C:\xampp\htdocs\SMTPmail (1)\SMTPClass.php on line 68
code not working sir...in my server. in above code i given echo "message sucess.."; here its show's only echo message..but not send my mail what i do?
ReplyDeleteplease help me..
How come this works on xampp on Windows, but does not work on httpd on CentOS?
ReplyDeleteIs there any way to include multiple email id in cc
ReplyDeleteHow do i use Multiple to addresses
ReplyDeletelike $to = '[email protected],[email protected]';
it wouldn't work for me..
DeletePlease any one help me my mails are not sent i don't have any error...........
ReplyDeleteI implemented your script just entered my gmail account details and google smtp details port 465
ReplyDeletei didn't get any error b ut mail is still not sent
[From] => 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN XOAUTH
[To] => 250-ENHANCEDSTATUSCODES
[data] => 250-PIPELINING
[send] => 250-CHUNKING
thank uuuuuuuuu to all guyzzz
ReplyDeleteWarning: fsockopen() [function.fsockopen]: unable to connect to 127.0.0.1:25 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ) in C:\Program Files\xampp\htdocs\mail\SMTPClass.php on line 36
ReplyDeletethank u from development. what is this error:
ReplyDeleteWarning: fsockopen(): unable to connect to 127.0.0.1:25 (No connection could be made because the target machine actively refused it. ) in C:\wamp\www\mailgood\SMTPclass.php on line 28
Hi , I used this code.no error.but mail not sending..Pls help me.
ReplyDeletesame Error:
ReplyDeleteI used this code.no error.but mail not sending..Pls help me.
how can i get confirmation message either mail sent or not
Nice post...you saved mah day..thanku a lotsss
ReplyDeletearray(8) { ["hello"]=> string(81) "220-md-in-31.webhostbox.net ESMTP Exim 4.86 #2 Sat, 23 Jan 2016 09:45:06 +0000 " ["res"]=> string(75) "220-We do not authorize the use of this system to transport unsolicited, " ["user"]=> string(25) "220 and/or bulk e-mail. " ["pass"]=> string(77) "250-md-in-31.webhostbox.net Hello md-in-31.webhostbox.net [111.118.215.254] " ["From"]=> string(19) "250-SIZE 52428800 " ["To"]=> string(14) "250-8BITMIME " ["data"]=> string(16) "250-PIPELINING " ["send"]=> string(22) "250-AUTH PLAIN LOGIN " }
ReplyDelete: Undefined variable: HTTP_HOST in C:\xampp\htdocs\SMTPmail\SMTPClass.php on line 38
ReplyDeletefputs ($SMTPIN, "HELLO " .$HTTP_HOST."\r\n");
in this line
hello srinivash I am facing problem in godaddy mailer its work perfect but when I try customize it throught error I want filed as name,email mobile and message when
ReplyDeleteplease watch my code
given below
when i include the file the mails are not going any solution??
ReplyDeleteSince it doesn't work with gmail, what email service should I use to receive the emails?
ReplyDeletethank you in advance !
Thank you. I was frantically searching for solving smtp issue in mailing with php. Your program just worked, making life easy in setting up a website.
ReplyDeletethank uou so much
ReplyDeletenot showing me from email id
ReplyDeletehow can we add bcc in this script....please help
ReplyDeletei can't able to send html content can you any help me
ReplyDeleteso what will be the html code to connect those files?
ReplyDeletehi,
ReplyDeletei am getting this notice but not send email
Notice: fputs(): send of 12 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host
hi,
ReplyDeletei am getting this notice
Notice: fputs(): send of 12 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host
how to send html content can you any help me
ReplyDeletehow to send an email to more that one user (to)?
ReplyDeletehow to send to more than one recipients?
ReplyDeleteHow to redirect to another page by submitting the form at SMTPClass?
ReplyDeleteNo error, but also not sending. Where could an error be? I created a new email address as well to use for SMTP but nothing seem to work. Any help?
ReplyDeleteHey guys,
ReplyDeleteI'm getting no subject in the header, can anyone suggest a solution please?
Great ....this code are working ...but it can't send html message (with html code) ....can you help me for this
ReplyDelete