简体   繁体   English

MAMP PRO PHP邮件 - Gmail

[英]MAMP PRO PHP Mail - Gmail

Hi I´m trying to send mails on localhost to my gmail account. 嗨我正在尝试将localhost上的邮件发送到我的Gmail帐户。 I tried the postfix tutorial on the MAMP Pro website but that did not work for me. 我在MAMP Pro网站上尝试了后缀教程,但这对我不起作用。

Is there any way to enable sending mails from and to my gmail-account on localhost? 有没有办法在localhost上从我的gmail帐户发送邮件?

I think you will want to authenticate and send directly with the gmail server. 我想您需要进行身份验证并直接使用gmail服务器发送。 For reasons related to spam prevention, I have seen issues with sending from a local machine to and from my gmail account. 出于与垃圾邮件防护相关的原因,我发现从本地计算机发送到我的Gmail帐户和从我的Gmail帐户发送的问题。

You could check out the PEAR Mail package . 您可以查看PEAR Mail包 Using it is fairly simple (code borrowed from another site): 使用它非常简单(从其他站点借来的代码):

<?php require_once "Mail.php";  
$from = "Sandra Sender <sender@example.com>"; 
$to = "Ramona Recipient <recipient@example.com>"; 
$subject = "Hi!"; 
$body = "Hi,\n\nHow are you?";  
$host = "ssl://mail.example.com"; 
$port = "465"; 
$username = "smtp_username"; 
$password = "smtp_password";  

$headers = array ('From' => $from,   
                  'To' => $to,   
                  'Subject' => $subject); 
$smtp = Mail::factory('smtp',   
                      array ('host' => $host,     
                             'port' => $port,     
                             'auth' => true,     
                             'username' => $username,     
                             'password' => $password));  

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

if (PEAR::isError($mail)) {   
    echo("<p>" . $mail->getMessage() . "</p>");  
} else {   
    echo("<p>Message successfully sent!</p>");  
} 
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM