Send Mail using SMTP and PHP.
Wall Script
Wall Script
Monday, October 12, 2009

Send Mail using SMTP and PHP.

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.

Send Mail using SMTP and PHP
This tutorial contains three files.

- Index.php
- SMTPconfig.php // SMTP Server Cofiguration
- SMTPClass.php // SMTP Mail Sending Class



Updated: Send mail using Gmail SMTP using PHP

Download Script



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
web notification

161 comments:

  1. Thanks. Very useful.

    ReplyDelete
  2. a piece of great code, thanks.

    by the way, is there method to default the coding of the email as unicode(UTF8)?

    ReplyDelete
  3. does this work for gmail smtp servers?

    ReplyDelete
  4. 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)

    ReplyDelete
  5. does it work for aol smtp server?

    ReplyDelete
  6. Notice: Undefined variable: HTTP_HOST in C:\wamp\www\1010\SMTPclass.php on line 30

    ReplyDelete
  7. Thanks,
    I really search for this script form last 1 week & i fount this script work fine for me.
    Thanks again.

    ReplyDelete
  8. Thank you very much for this useful class, how can we use it to send HTML emails?


    @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...

    ReplyDelete
  9. i'm getting this error:
    Notice: Undefined variable: HTTP_HOST in /var/www/vhosts/cutrin.lt/httpdocs/evelita/mailtest/SMTPClass.php on line 30

    ReplyDelete
  10. Thanks youuuuuuuuuuu.....

    ReplyDelete
  11. this not support html mail

    ReplyDelete
  12. problem when I send subject in arabic
    How i solve it?

    ReplyDelete
  13. SMTPClass.php is not SMTPclass.php
    Your script and include files names do not match,

    ReplyDelete
  14. 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

    Fatal error: Maximum execution time of 60 seconds exceeded in D:\xampp\htdocs\NetBill Manager\admin\SMTPClass.php on line 28

    ReplyDelete
  15. please help me to include headers
    Ex: $headers = "Content-Transfer-Encoding: 8bit\r\n";
    $headers .= 'Content-Type: text/html; charset="iso-8859-1"'."\r\n";

    ReplyDelete
  16. Notice: Undefined variable: HTTP_HOST in .../SMTPclass.php on line 30

    ReplyDelete
  17. 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

    ReplyDelete
  18. i copied the three php programs and wen i try to run the index.php file it in d wamp server,
    its 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....

    ReplyDelete
  19. Nice post..

    You 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 !!!

    ReplyDelete
  20. Reza Said:
    how can I send email to more than one person on one textbox ?

    ReplyDelete
  21. 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.


    SmtpServer = $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;
    }
    }
    ?>

    ReplyDelete
  22. 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?

    ReplyDelete
  23. Mails are going to Spam box. can you help me resolve it.

    ReplyDelete
  24. I am getting this error please help me to solve


    Undefined variable: HTTP_HOST in C:\wamp\www\smtp\SMTPclass.php on line 39

    ReplyDelete
  25. Does 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?

    ReplyDelete
  26. heh.. 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:
    2011-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

    ReplyDelete
  27. thnx for this class ,
    but how can i get a confirmation message
    if mail fails to b delivered then how can i get to know about that ??

    ReplyDelete
  28. Hi,

    All..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

    ReplyDelete
  29. Thank you

    it is excellent .

    But how to set server inside config file to send Email to yahoo ?

    ReplyDelete
  30. Nice job,

    this code worked beautifully for me to connect to godaddys smtp

    ReplyDelete
  31. I have tried this and its working properly. Is it possible to add attachment when sending an email using smtp? Thanks. :)

    ReplyDelete
  32. nice script. but can u plz help me out on the attachment issue?

    ReplyDelete
  33. to solve problem of "Undefined variable: HTTP_HOST"
    replace it with "getenv('MyHost')", it worked well with me...


    and i am reallly grateful for this post..thank you soooo much (^_^)

    ReplyDelete
  34. regarding the SMTPconfig.php... ca we put mail.domain.com at $SmtpServer? something like this:


    any help?

    ReplyDelete
  35. 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:

    "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. "

    ReplyDelete
  36. Thanks a lot. You are the man!

    ReplyDelete
  37. the line

    $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.

    ReplyDelete
  38. Very very thankful for your valuable post

    ReplyDelete
  39. Thank you so much!! That's what i need.. very3 thank you...

    ReplyDelete
  40. I copy and paste code and make some change the script run successfully but email not received by client.

    please help
    thank in ad..

    ReplyDelete
  41. Works like a charm thanks!

    ReplyDelete
  42. index.php downloads instead of opening....

    ReplyDelete
  43. @Elite Web Services: you have to open the file on a web server

    ReplyDelete
  44. Hello. Nice class. How can i send mail to multiple users? i use such codes: fputs ($SMTPIN, "RCPT TO: , , \r\n");
    But 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.

    ReplyDelete
  45. 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 ?

    ReplyDelete
  46. Sorry, i did some mistaken on header. now already work in accordingly. Thank you !

    ReplyDelete
  47. Sorry, i did some mistaken on header. now already work in accordingly. Thank you !

    ReplyDelete
  48. Okay, my solution for HTML and a Bcc which you could change to Cc easily.

    index.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

    ReplyDelete
  49. Alongside that, I forgot to mention in index.php you'll need to add this just before the function is called:

    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    This will send it as HTML

    ReplyDelete
  50. Thanks alot it still pending when i send email to gmail !

    ReplyDelete
  51. problem when I send subject in arabic
    How to solve it?

    ReplyDelete
  52. [data] => 500 Syntax error, command unrecognized [send] => 250 OK.
    This is what am getting in my array SMTPChat and cant understand why?

    ReplyDelete
  53. 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

    Fatal error: Maximum execution time of 60 seconds exceeded in C:\Program Files\xampp\htdocs\Email\SMTPclass.php on line 28

    ReplyDelete
  54. Notice: Undefined variable: HTTP_HOST

    ReplyDelete
  55. Great PHP I love it.
    canyou plase show us how to send a attachment like a picture orother file.
    this make the cookies better.
    best regards
    Gil

    ReplyDelete
  56. How Can BCC part can be added to this and email can be sent group of people at once?

    ReplyDelete
  57. Notice: Undefined variable: HTTP_HOST in C:\xampp\htdocs\SMTPclass.php on line 30

    Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\SMTPclass.php on line 31 error

    ReplyDelete
  58. hi all i am getting an SMTP Error: Could not connect to SMTP host. my mail function is


    function 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

    ReplyDelete
  59. Ok, after hours of struggling i have working solution with attachments...

    Here 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!

    ReplyDelete
  60. Hi ,

    I`m getting 530 error .
    Reason: Remote host said: 530 SMTP authentication is required.

    ReplyDelete
  61. i cannot send mail...please help..
    tried the sript.. changed the server setails etc.. but mail not received

    ReplyDelete
  62. Undefined variable: HTTP_HOST in C:\wamp\www\smtp\SMTPclass.php on line 39

    ReplyDelete
  63. 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
    Call 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 :

    ReplyDelete
  64. Hi guys. I am new to php coding and creating contact form for the first time.
    I 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?

    ReplyDelete
  65. if ('SMTPconfig.php' == basename($_SERVER['SCRIPT_FILENAME']))
    die ('Direct File Access Prohibited');
    add above into head of SMTPconfig.php to prevent direct access.

    ReplyDelete
  66. 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.
    Do i need to install any mail package?

    VP

    ReplyDelete
  67. Hello Srinivas Tamada
    First 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!

    ReplyDelete
  68. Hi Diego,

    After $SMTPChat = $SMTPMail->SendMail(); put something like:
    $sent = true;

    then instead of if(SendMail)use if($success == true) {

    ReplyDelete
  69. Thanks man, had this problem with cent os + mantis (new installation wich I didn't made). You helped me good !

    Thx !

    ReplyDelete
  70. i can connect smptp,but I can't receive the email I sent, why?
    whats the problem?

    ReplyDelete
  71. unable to use ,getting warning as
    Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in XXXXX

    Please help.

    ReplyDelete
  72. but its not working for gmail smtp plz
    help me

    ReplyDelete
  73. gd coding but it is not working....so plz help me

    ReplyDelete
  74. i can connect smptp,but I can't receive the email I sent, why?
    whats the problem?

    ReplyDelete
  75. I am having the same problem as Zeihan Aulia:

    "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??

    ReplyDelete
  76. 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

    ReplyDelete
  77. First of all thanks for your nice codings. I used your emailing code and its working fine.

    Please 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.

    ReplyDelete
  78. Notice: Undefined variable: HTTP_HOST in E:\wamp\www\lastmail\SMTPClass.php on line 38

    ReplyDelete
  79. Hello, very nice and useful. Thanks for the great script.
    1.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

    ReplyDelete
  80. Hello,

    At 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?

    ReplyDelete
  81. Thanks ! Nice way to send mail

    -Anup

    ReplyDelete
  82. Notice: Undefined variable: HTTP_HOST in C:\wamp\www\SMTPmail\SMTPClass.php
    aidez moi svp

    ReplyDelete
  83. its still. I have tried your code for sending html. it is not sending as html email

    ReplyDelete
  84. Hello!
    I'm french and i want to sent mail with accent!
    How can I do this?

    Please help me!

    Thank you!!

    ReplyDelete
  85. Please Help me! It is very urgent! TT_TT

    ReplyDelete
  86. can you post full code to send as HTML mail

    ReplyDelete
  87. I have found alone...^^

    You 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!!!

    ReplyDelete
  88. i'm getting this error:
    Warning: 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.

    ReplyDelete
  89. Hello! There is a fault!

    You 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!!

    ReplyDelete

  90. Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\test\SMTPmail\SMTPClass.php on line 39

    ReplyDelete
  91. Error :Notice: Undefined variable: HTTP_HOST in C:\xampp\htdocs\SMTPclass.php on line 30
    plzz help

    ReplyDelete
  92. i tried this. nothing happens..

    ReplyDelete
  93. For the Error:

    Error :Notice: Undefined variable: HTTP_HOST in

    Please change:
    fputs ($SMTPIN, "EHLO ".HTTP_HOST."\r\n");

    for
    fputs ($SMTPIN, "EHLO ".$_SERVER["HTTP_HOST"]."\r\n");

    ReplyDelete
  94. 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 ?

    Here is my working script

    ReplyDelete
  95. Very nice script.

    When 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?

    ReplyDelete
  96. Mr.admin im getting this error..

    Warning: 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...

    ReplyDelete
  97. Script is working Fine..

    How to change body of the content html template?

    ReplyDelete
  98. 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


    i got this error on smtp mail


    plz any one send the correct smtp mail code on my mail

    [email protected]

    plzzzzzzzzzzzzzzz help me

    ReplyDelete
  99. really really TY man!!!!!!! seriously

    ReplyDelete
  100. from where to buy SMTP server Can we get free

    ReplyDelete
  101. data are not specified using the SMTP server, or you need to edit something for which SMTP server to use

    ReplyDelete
  102. Its working perfectly. Thank you

    Now i just need to try the code for attachments

    ReplyDelete

  103. ( ! ) 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

    ReplyDelete
  104. can i send email on yahoo or gmail using this script

    ReplyDelete
  105. Hi... plz someone help for secured SSL email using gmail SMTP.

    ReplyDelete
  106. 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\mail\SMTPClass.php on line 35 why this warning is coming

    ReplyDelete
  107. Mail showing html tags, what is the error???

    ReplyDelete
  108. I have a problem
    When input user & password is error.
    How get error info & send success or fail

    ReplyDelete
  109. Hello Experts I am fresher in php. I need your help. Please guide me.

    I 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

    ReplyDelete
  110. How can we use recaptcha with this script?

    ReplyDelete
  111. how can to at a time all user send mail script

    ReplyDelete
  112. PHP Fatal error: Class 'SMTPClient' not found in /home/banlabco/public_html/SMTP/index.php on line 10

    ReplyDelete
  113. send two mail different email id on my smtp sendmail function

    ReplyDelete
  114. Warning: 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

    Notice: Undefined variable: talk in C:\xampp\htdocs\SMTPmail (1)\SMTPClass.php on line 68

    ReplyDelete
  115. 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?
    please help me..

    ReplyDelete
  116. How come this works on xampp on Windows, but does not work on httpd on CentOS?

    ReplyDelete
  117. Is there any way to include multiple email id in cc

    ReplyDelete
  118. Please any one help me my mails are not sent i don't have any error...........

    ReplyDelete
  119. I implemented your script just entered my gmail account details and google smtp details port 465
    i 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

    ReplyDelete
  120. Warning: 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

    ReplyDelete
  121. thank u from development. what is this error:
    Warning: 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

    ReplyDelete
  122. Hi , I used this code.no error.but mail not sending..Pls help me.

    ReplyDelete
  123. same Error:
    I used this code.no error.but mail not sending..Pls help me.
    how can i get confirmation message either mail sent or not

    ReplyDelete
  124. Nice post...you saved mah day..thanku a lotsss

    ReplyDelete
  125. array(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
  126. : Undefined variable: HTTP_HOST in C:\xampp\htdocs\SMTPmail\SMTPClass.php on line 38

    fputs ($SMTPIN, "HELLO " .$HTTP_HOST."\r\n");

    in this line

    ReplyDelete
  127. 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


    please watch my code

    given below

    ReplyDelete
  128. when i include the file the mails are not going any solution??

    ReplyDelete
  129. Since it doesn't work with gmail, what email service should I use to receive the emails?
    thank you in advance !

    ReplyDelete
  130. 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.

    ReplyDelete
  131. how can we add bcc in this script....please help

    ReplyDelete
  132. i can't able to send html content can you any help me

    ReplyDelete
  133. so what will be the html code to connect those files?

    ReplyDelete
  134. hi,
    i 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

    ReplyDelete
  135. hi,
    i am getting this notice

    Notice: fputs(): send of 12 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host

    ReplyDelete
  136. how to send html content can you any help me

    ReplyDelete
  137. how to send an email to more that one user (to)?

    ReplyDelete
  138. how to send to more than one recipients?

    ReplyDelete
  139. How to redirect to another page by submitting the form at SMTPClass?

    ReplyDelete
  140. No 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?

    ReplyDelete
  141. Hey guys,

    I'm getting no subject in the header, can anyone suggest a solution please?

    ReplyDelete
  142. Great ....this code are working ...but it can't send html message (with html code) ....can you help me for this

    ReplyDelete

mailxengine Youtueb channel
Make in India
X