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

This is my coding ..but output is message send failed.. so what can i do???

Mari
  • 1

3 Answers3

0

You need to configure SMTP on localhost for sending email

Go to your php.ini and set below settings

[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
 SMTP = mail.host.com 
 smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = postmaster@localhost

For more :- WAMP send Mail using SMTP localhost

Community
  • 1
  • 1
Rakesh Sharma
  • 13,680
  • 5
  • 37
  • 44
  • [mail function] ; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury SMTP = mail.host.com smtp_port = 25 ; For Win32 only. ; http://php.net/sendmail-from sendmail_from = postmaster@localhost This coding is wirght or wrong?? – Mari Nov 10 '14 at 05:32
  • you need to set your mail server host SMTP = mail.host.com – Rakesh Sharma Nov 10 '14 at 06:48
0

The right method of sending mail in php is via pear mail extension . PEAR_MAIL

Then you can follow the steps : 1)Install pear : click on pear.phar or pear.bet in php folder

2)set REG.ENV, if it doesn work , change environment variable : PHP_PEAR_PHP_BIN to %pathWherePhpIsInstalled/php.exe

3)install mail package

4)install net_smtp package

Sample Mail Script :

$from = 'senderemailaddress';
$to = 'mass.mari06@gmail.com';
$subject = 'Hi,Its subject!';
$body = "Hi,\n\nHow are you?";

$headers = array(
    'From' => $from,
    'To' => $to,
    'Subject' => $subject
);

$smtp = Mail::factory('smtp', array(
    'host' => 'ssl://smtp.gmail.com',
    'port' => '465',
    'auth' => true,
    'username' => 'sender_email_addreess',
    'password' => 'pass'
));

$mail = $smtp->send($to, $headers, $body);

    if (PEAR::isError($mail)) {
    echo('<p>' . $mail->getMessage() . '</p>');
} else {
    echo('<p>Message successfully sent!</p>');
}
?>
Vivek Mishra
  • 350
  • 2
  • 12
  • how can i get pear installer?? anylink available?? – Mari Nov 10 '14 at 05:40
  • Pear- http://pear.php.net/manual/en/installation.getting.php install pear from the given instruction on the page set environment varibles as stated above . run command pear install mail package pear install net_smtp package Then Run the above script . Its fun , just try . – Vivek Mishra Nov 10 '14 at 06:01
0

There are two ways of sending emails. SMTP or php mail function.According to your code, you are using the php mail function.

Difference:

SMTP uses other vendor's Mail Transport Agent (MTA).

php mail function uses your own Mail Transport Agent (MTA).

Mail Transport Agent (MTA) is one kind of software, for instance, sendmail in Linux. It is not easy to setup a MTA on windows. If you just need to debug the output content of the mail, I suggest you use this tool, Test Mail Server Tool

JasonW
  • 453
  • 1
  • 9
  • 16