[英]MAMP PRO PHP Mail - Gmail
嗨我正在嘗試將localhost上的郵件發送到我的Gmail帳戶。 我在MAMP Pro網站上嘗試了后綴教程,但這對我不起作用。
有沒有辦法在localhost上從我的gmail帳戶發送郵件?
我想您需要進行身份驗證並直接使用gmail服務器發送。 出於與垃圾郵件防護相關的原因,我發現從本地計算機發送到我的Gmail帳戶和從我的Gmail帳戶發送的問題。
您可以查看PEAR Mail包 。 使用它非常簡單(從其他站點借來的代碼):
<?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.