如何从localhost "wamp"发送电子邮件;php


how to send email from localhost "wamp" by php?

我尝试通过这个php代码从wampserver "localhost"发送电子邮件

<?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!'); 
}
?>

我使用的文件sendmail,并把它放在文件"C:'wamp'sendmail"我改变设置sendmail.ini文件->

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更改了在C:'wamp'bin'apache'apache2.2.22'bin中设置php.ini文件和我改变了设置php.ini文件在C:'wamp'bin'php'php5.4.3

[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更改了设置appach module" SSL module" checked

和我改变设置PHP扩展" PHP openssl" &"php sockets"

和它不工作的代码没有发送电子邮件

在网上讨论了很多,尝试了很多方法为什么不发生发射机和正确的方式是什么为我的英语错误道歉请帮忙,谢谢

PHPMailer一直为我在开发服务器(localhost)以及现场网站上工作。

在这里下载PHPMailer,解压缩并放到应用程序的目录中。

当你想发送邮件时,使用以下代码:

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:您应该更新PHP安装以使其正常工作。对于你得到的错误,试试这个:

在php.ini中搜索 行
; extension=php_openssl.dll

和remove;所以它变成了:

extension=php_openssl.dll

这个适合我:

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