0

I want to send a mail from my php script using mail function.so i installed Wamp

and did setting in sendmail.ini and php.ini using this link

When i run my php program its giving:

Email sending failed

my php program is as follows:

<?php
$to       = 'xyz@gmail.com'; /* here i added email id of person which i want to send mail */
$subject  = 'Testing sendmail.exe';
$message  = 'Hi, you just received an email using sendmail!';
$headers  = 'From: myid@gmail.com' . "\r\n" .
            'Reply-To: myid@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";
?>

So i am not getting where i am wrong. Can any one help me on this.

Thank you.

snehal
  • 429
  • 5
  • 11
  • 25

2 Answers2

0

You did'nt depend any kind off server wamp, xammp or else you just use class phpmailer with this code or modify according to you

<?php

require 'class.phpmailer.php';
$mail = new PHPMailer;

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup server
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'akkyverma';                            // SMTP username
$mail->Password = 'password';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also        

$mail->From = 'akkyverma@gmail.com';
$mail->FromName = 'Mailer';
$mail->addAddress('ankit_verma@example.net', 'ankit verma');  // Add a recipient
$mail->addAddress('ankit_add@example.com');               // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->WordWrap = 50;                                 // Set word wrap to 50 characters
$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}

echo 'Message has been sent';

just use an object LIke $mail to send a email or send emails with multiple TOs, CCs, BCCs and REPLY-TOs. check The classic email sending library for PHP Github

ankit verma
  • 168
  • 11
  • php mailer available on above GitHub Link – ankit verma Oct 11 '13 at 06:51
  • thank you @ankit verma. i follows above thing. when i run this script this is giving me following error. Warning: stream_socket_enable_crypto(): this stream does not support SSL/crypto in C:\xampp\htdocs\sendmail\class.smtp.php on line 274 Message could not be sent.Mailer Error: SMTP connect() failed. please help me one this. thank you – snehal Oct 11 '13 at 07:45
  • thank you @ankit verma. i removed semicolon from extension=php_openssl.dll in php.ini file . it works ... thank you so much – snehal Oct 11 '13 at 08:01
0

You need to enable OpenSSL extension in your WAMP setup.

I see you uncommented this line: extension=php_openssl.dll which is good, but apparently Wampserver with apache 2.4.4 released with wrong OpenSSL files!

Aditya P Bhatt
  • 21,431
  • 18
  • 85
  • 104