簡體   English   中英

使用 PHP 發送電子郵件,在配置 SMTP 服務器時遇到問題

[英]Sending emails using PHP, having troubles configuring the SMTP server

嘗試為新注冊的用戶發送激活 email,這是到目前為止的代碼:

$to = $email;
$subject = "Activate your account!";
$headers = "From: noreply@test.com";    
$body = "..."

$mail($to, $subject, $body, $headers);

在 phpacademy 的教程中,講師使用

ini_set("SMTP", $server);

我不知道該怎么做。 我認為我的 SMTP 服務器應該是我的雅虎帳戶。 如何發送電子郵件?

不,您的帳戶服務器不同。 您的$server變量應設置為 SMTP 服務器的合適主機名或 IP 地址,例如$server = "mail.myisp.net"; .

檢查您的 email 客戶端以查找您自己的郵件服務器,或詢問您的 ISP。

$server應該是運行 SMTP 服務器守護進程並且您有權訪問的機器的名稱(或 IP 地址)。 這應該適用於雅虎的服務(可能類似於 smtp.yahoo.com),但如果您要去 email 的地址不是@yahoo.Z4D236AD1502D102C50Z6. 更常見的是使用本地服務器,就像您的辦公室/學校為您配置的一樣。 或者,如果您運行的是 unix-ish 操作系統,您可能可以完全跳過該行並讓它默認為 localhost。

如果您要發送 email 和 PHP 郵件 function 您必須在您的 PCCC 中設置第一個 ZC2239A92BDE29FFEA099 服務器。 其他方式,您可以使用 class 來執行此操作,而無需在 PC 中設置任何東西。 已知PHP 郵件程序只需幾行即可:這是項目站點的示例:

<?php

require("class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP();  // telling the class to use SMTP
$mail->Host     = "smtp.example.com"; // SMTP server

$mail->From     = "from@example.com";
$mail->AddAddress("myfriend@example.net");

$mail->Subject  = "First PHPMailer Message";
$mail->Body     = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;

if(!$mail->Send()) {
  echo 'Message was not sent.';
  echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
  echo 'Message has been sent.';
}
?> 

官方 web 網站: http://phpmailer.worxware.com

當我必須在用戶注冊后向用戶發送激活電子郵件時,我考慮過相同的 SMTP 路線,但即使你設法讓它繼續使用 SMTP 也有某些缺點

  1. 延遲發送電子郵件。
  2. 被視為垃圾郵件的電子郵件
  3. 配置等

試試這個,到目前為止,它對我來說是非常便宜和可靠的服務。 www.postmarkapp.com 他們有 API,您可以使用 PHP 掛鈎。 我在生產中的示例 PHP 代碼如下。

    // Create a "server" in your "rack", then copy it's API key
define('POSTMARKAPP_API_KEY', 'xyz-blah-blah-blah');

// Create a "Sender signature", then use the "From Email" here.
// POSTMARKAPP_MAIL_FROM_NAME is optional, and can be overridden
// with Mail_Postmark::fromName()
define('POSTMARKAPP_MAIL_FROM_ADDRESS', 'email address that you are sending from-google apps email in my case');
define('POSTMARKAPP_MAIL_FROM_NAME', 'Description of the Sender name');

// Create a message and send it
Mail_Postmark::compose()
    ->addTo($to, $to)
    ->subject('whatever subject you want to put here for your email')
    ->messagePlain($pin_message)
    ->send();

是的,一旦您使用 postmarkapp 創建了虛擬服務器,它就這么簡單。 猜猜前 1000 封電子郵件是免費的,因此您可以嘗試一下,如果沒有,請按照自己的方式使用 SMTP。 在前 1000 個之后,我認為 5000 個花費 7 美元或其他東西。 真的很好很便宜,我根本沒有停機時間。

試試看。 你會喜歡它。 順便說一句,我與郵戳無關,只是因為我喜歡使用他們的服務。 看看我之前做這個的時候的問題。

PHP mail() function 發送 email 但需要超過 10 分鍾才能顯示

if you're on a linux server you should check that the server as a smtp server installed, if not you'd better configure one in the php.ini http://fr.php.net/manual/en/mail.configuration .php

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM