簡體   English   中英

來自地址的php郵件(Net / SMTP.php)無法正常工作

[英]php mail(Net/SMTP.php) from address not working

我正在使用php mail(Net / SMTP.php)處理表單,一切正常,它可以發送電子郵件,唯一的問題是,當我查看收件箱中的電子郵件時,它表示沒有發件人。 您可以在我的程序中看到我設置了發件人地址。 我正在使用共享主機,我的共享主機提供商是planethippo。

    <?php
ini_set("include_path", '/home/gaborszi/php:' . ini_get("include_path") );

echo htmlspecialchars($_POST['name']);

require 'Net/SMTP.php';

$host = 'localhost';
$from = 'gaborszita@gaborszita.tk';
$rcpt = array('gaborszita@yahoo.com', 'gaborszita@gaborszita.tk');
$subj = "Subject: Test Message\n";
$body = "Name: " . htmlspecialchars($_POST['name']);

/* Create a new Net_SMTP object. */
if (! ($smtp = new Net_SMTP($host))) {
    die("Unable to instantiate Net_SMTP object\n");
}

/* Connect to the SMTP server. */
if (PEAR::isError($e = $smtp->connect())) {
    die($e->getMessage() . "\n");
}
$smtp->auth('gaborszita@gaborszita.tk','mypassword');
/* Send the 'MAIL FROM:' SMTP command. */
if (PEAR::isError($smtp->mailFrom($from))) {
    die("Unable to set sender to <$from>\n");
}

/* Address the message to each of the recipients. */
foreach ($rcpt as $to) {
    if (PEAR::isError($res = $smtp->rcptTo($to))) {
        die("Unable to add recipient <$to>: " . $res->getMessage() . "\n");
    }
}

/* Set the body of the message. */
if (PEAR::isError($smtp->data($subj . "\r\n" . $body))) {
    die("Unable to send data\n");
}

/* Disconnect from the SMTP server. */
$smtp->disconnect();

我的收件箱圖片

我還在服務器上使用PEAR。 我對這行感到困惑:“ $ rcpt = array('gaborszita@yahoo.com','gaborszita@gaborszita.tk');”。 我有一個類似的代碼,使用$ email_to =“ one.address@sample.com,two.address@sample.com”; 並且兩個地址都收到一個副本。 我的代碼還包括一個真正的發送者$ from_address。 該地址是我為向我發送表格數據而設置的電子郵件帳戶。

暫無
暫無

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

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