-1

I want to generate email using localhost and php in windows . I have installed wamp server and tried but i got the following error

Socket Error # 11001Host not found.

The code is

 <?php
    $to       = 'name@gmail.com';
    $subject  = 'Testing sendmail.exe';
    $message  = 'Hi, you just received an email using sendmail!';
    $headers  = 'From: username@gmail.com' . "\r\n" ;
                'Reply-To: name@gmail.com' . "\r\n" .
     $headers .= 'MIME-Version: 1.0' . "\r\n" ;
     $headers .  'Content-type: text/html; charset=iso-8859-1' . "\r\n" ;
      $headers . 'From: username@gmail.com' . "\r\n" ;
                'X-Mailer: PHP/' . phpversion();
    if(mail($to,$subject,$message,$headers))
        echo "Email sent";
    else
        echo "Email sending failed";

                ?>

3 Answers3

1

This solution requires sendmail.exe (a Command Line Interface (CLI) executable which accepts email from PHP, connects to an SMTP server and sends email). You will not require to use it by command, don’t bother about it :-) Download the sendmail.zip1 and follow these steps:

Create a folder named “sendmail” in “C:\wamp\”.
Extract these 4 files in “sendmail” folder: “sendmail.exe”, “libeay32.dll”, “ssleay32.dll” and “sendmail.ini”.
Open the “sendmail.ini” file and configure it as following
    smtp_server=smtp.gmail.com
    smtp_port=465
    smtp_ssl=ssl
    default_domain=localhost
    error_logfile=error.log
    debug_logfile=debug.log
    auth_username=[your_gmail_account_username]@gmail.com
    auth_password=[your_gmail_account_password]
    pop3_server=
    pop3_username=
    pop3_password=
    force_sender=
    force_recipient=
    hostname=localhost

and visit link:-http://blog.techwheels.net/send-email-from-localhost-wamp-server-using-sendmail/

You do not need to specify any value for these properties: pop3_server, pop3_username, pop3_password, force_sender, force_recipient. The error_logfile and debug_logfile settings should be kept blank if you have already sent successful email(s) otherwise size of this file will keep increasing. Enable these log file settings if you don’t get able to send email using sendmail.

step1:Enable IMAP Access in your GMail’s Settings -> Forwarding and POP/IMAP -> IMAP Access:

step2:Open php.ini from “C:\wamp\bin\apache\Apache2.2.17\bin” and configure it as following (The php.ini at “C:\wamp\bin\php\php5.3.x” would not work) (You just need to configure the last line in the following code, prefix semicolon (;) against other lines):

step 4: Restart WAMP Server.

step 5:Create a PHP file and write the following code in it:

`<?php
$to       = 'recipient@yahoo.com';
$subject  = 'Testing sendmail.exe';
$message  = 'Hi, you just received an email using sendmail!';
$headers  = 'From: [your_gmail_account_username]@gmail.com' . "\r\n" .
        'MIME-Version: 1.0' . "\r\n" .
        'Content-type: text/html; charset=utf-8';
if(mail($to, $subject, $message, $headers))
echo "Email sent";
else
echo "Email sending failed";
?>`

step 6: Make appropriate changes in $to and $headers variables to set recipient and sender (“From” header) addresses. Save it as “send-mail.php”. (You can save it anywhere or inside any sub-folder in “C:\wamp\www”.)

step 7:Open this file in browser, it MUST work now :-)

Ashvin Monpara
  • 282
  • 5
  • 19
0

You can use PHPMailer form mailing. Download from https://github.com/Synchro/PHPMailer or https://github.com/PHPMailer/PHPMailer

GAMITG
  • 3,810
  • 7
  • 32
  • 51
0

in sendmail.ini

smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=ssl
default_domain=localhost
error_logfile=error.log
debug_logfile=debug.log
auth_username=[your_gmail_account_username]@gmail.com
auth_password=[your_gmail_account_password]
pop3_server=
pop3_username=
pop3_password=
force_sender=
force_recipient=
hostname=localhost

and

image

in php.ini

[mail function]
; For Win32 only.
; http://php.net/smtp
;SMTP = 
; http://php.net/smtp-port
;smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = you@domain.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "C:\wamp\sendmail\sendmail.exe -t -i"

Restart WAMP Server.

Sample mail Code

<?php
$to       = 'recipient@yahoo.com';
$subject  = 'Testing sendmail.exe';
$message  = 'Hi, you just received an email using sendmail!';
$headers  = 'From: [your_gmail_account_username]@gmail.com' . "\r\n" .
            'MIME-Version: 1.0' . "\r\n" .
            'Content-type: text/html; charset=utf-8';
if(mail($to, $subject, $message, $headers))
    echo "Email sent";
else
    echo "Email sending failed";
?>

More Idea

  1. Stack Asnwer
Community
  • 1
  • 1
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85