0

I try to send email from wampserver "localhost" by this php code

<?php

$to      = 'test1@gmail.com'; 
$subject = 'Fake sendmail test'; 
$message = 'If we can read this, it means that our fake Sendmail setup works!'; 
$headers = 'From: test2@gmail.com' . "\r\n" . 
'Reply-To: eng.jirjawi@gmail.com' . "\r\n" . 
'X-Mailer: PHP/' . phpversion(); 

if(mail($to, $subject, $message, $headers)) { 
echo 'Email sent successfully!'; 
} else { 
die('Failure: Email was not sent!'); 
}

?>

I used the file "sendmail" and put it inside the file "C:\wamp\sendmail" i changed setting sendmail.ini file to -->

smtp_server=smtp.gmail.com

smtp_port=465

smtp_ssl=ssl

default_domain=localhost

error_logfile=error.log

auth_username=test2@gmail.com
auth_password=xxxxxxx

pop3_server=
pop3_username=
pop3_password=

force_sender=

force_recipient=

hostname=localhost

i changed setting php.ini file in C:\wamp\bin\apache\apache2.2.22\bin and i changed setting php.ini file in C:\wamp\bin\php\php5.4.3 to

[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@yourdomain

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

and i changed setting appach module "SSL module" checked

and i changed setting php extension "php openssl" & "php sockets"

And it did not work with the code did not send email

Discussed a lot in the internet and tried many ways Why does not happen transmitter and what the correct way Apologized for the mistakes my English language Please help and thank you

AnFi
  • 10,493
  • 3
  • 23
  • 47
jirjawi
  • 1
  • 1
  • 3

2 Answers2

2

PHPMailer has always worked for me on development servers (localhost), as well as on live websites.

Download PHPMailer here, unzip it and put it in your application's directory.

When you want to send a mail, use the following code :

require 'PHPMailerAutoload.php'; //Your path to PHPMailer's directory
$Mail = new PHPMailer();
$Mail->IsSMTP(); // Use SMTP
$Mail->Host        = "smtp.gmail.com"; // Sets SMTP server for gmail
$Mail->SMTPDebug   = 0; // 2 to enable SMTP debug information
$Mail->SMTPAuth    = TRUE; // enable SMTP authentication
$Mail->SMTPSecure  = "tls"; //Secure conection
$Mail->Port        = 587; // set the SMTP port to gmail's port
$Mail->Username    = 'yourusername@gmail.com'; // gmail account username
$Mail->Password    = 'yourpassword'; // gmail account password
$Mail->Priority    = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 =   low)
$Mail->CharSet     = 'UTF-8';
$Mail->Encoding    = '8bit';
$Mail->Subject     = 'Mail test';
$Mail->ContentType = 'text/html; charset=utf-8\r\n';
$Mail->From        = 'test2@gmail.com'; //Your email adress (Gmail overwrites it anyway)
$Mail->FromName    = 'Test';
$Mail->WordWrap    = 900; // RFC 2822 Compliant for Max 998 characters per line

$Mail->addAddress('test1@gmail.com'); // To: test1@gmail.com
$Mail->isHTML( TRUE );
$Mail->Body    = '<b>This is a test mail</b>';
$Mail->AltBody = 'This is a test mail';
$Mail->Send();
$Mail->SmtpClose();

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

echo 'Message has been sent';

Update : You should update your PHP installation for this to work correctly. For the error you're getting, try this :

In your php.ini search for line

; extension=php_openssl.dll

and remove ; so it becomes:

extension=php_openssl.dll
Abhishek Goyal
  • 867
  • 1
  • 7
  • 21
  • Thanx for help me but when tried show me error "SCREAM: Error suppression ignored for" & " Warning: stream_socket_enable_crypto(): this stream does not support SSL/crypto in C:\wamp\www\gmail\class.smtp.php on line 273" what is th solution ?? – jirjawi May 08 '14 at 12:00
  • Unfortunately did not work !! this my files see them https://www.dropbox.com/s/k1tru8jl5ploi7z/php.ini https://www.dropbox.com/s/hzxe4ckhjrnxss9/sendmail.ini – jirjawi May 08 '14 at 12:40
  • @user3157544, set SMTPDebug=2 and then update your answer with the result that you are getting. – Abhishek Goyal May 08 '14 at 12:44
-1

This works for me:

<?php
if ($_SERVER["REQUEST_METHOD"] == 'POST'){
    //print_r($_POST);
    if (mail('name@example.com', 'New Test Email', htmlspecialchars($_POST['msg']))){
        $cas = "thanks for the msg";
    }

 } 
?>

<!doctype html>
<html>
<head> <title>my test company</title>
</head>
<body>
<h3>Contactez nous</h3>
<form action="" method="post">
    <ul>
        <li>
            <label for="name">Name:</label>
            <input type="text" name="name" id="name">
        </li>
        <li>
            <label for="email">Email :</label>
            <input type="text" name="email" id="email">
        </li>
        <li>
            <label for="msg">Message:</label><br />
            <textarea name="msg" id="msg"></textarea>
        </li>
                
        <li>
            <input type="submit" value="Go!">
        </li>
    </ul>
</form>
<?php 
if (isset($cas)) echo $cas; 
?>
</body>
</html>
CompScien
  • 1
  • 1