apache 如何通过php从localhost“wamp”发送电子邮件?

3zwjbxry  于 2023-05-23  发布在  Apache
关注(0)|答案(2)|浏览(136)

我尝试从wampserver发送电子邮件“localhost”由这个php代码

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

我将C:\wamp\bin\apache\apache2.2.22\bin中的php.ini文件设置更改为C:\wamp\bin\php\php5.4.3中的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@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"

和我改变设置appach模块“SSL模块”检查
我改变了设置php扩展“php openssl”&“php套接字”
并且它没有工作与代码没有发送电子邮件
讨论了很多在互联网上,并尝试了许多方法,为什么不发生发射机和什么正确的方式道歉的错误,我的英语请帮助,谢谢你

dvtswwa3

dvtswwa31#

PHPMailer一直在开发服务器(本地主机)和实时网站上为我工作。
下载PHPMailerx 1 e1f1x,解压缩并将其放到应用程序的目录中。
当你想发送一封邮件时,使用下面的代码:

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

更新:您应该更新您的PHP安装,以使其正常工作。对于您得到的错误,请尝试以下操作:
在php.ini中搜索行

; extension=php_openssl.dll

并移除;所以它变成了:

extension=php_openssl.dll
wb1gzix0

wb1gzix02#

这对我很有效:

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

相关问题