2011-03-16 57 views
3

在發送電子郵件的PHP腳本中存在一些問題(代碼如下)。基本上,它將存儲在sql數據庫中的聯繫人信息填充到vCard文件中,並使用php mail()函數將其附加到電子郵件中。未在新服務器上發送PHP郵件()函數

前幾天我曾在共享主機服務器上完美工作......但我最近將所有內容都遷移到了VPS,並且它神奇地停止了工作。 Mail()在發送時繼續返回true,但實際的電子郵件永遠不會到達我的收件箱。

//sendemail: emails a vCard when passed an email address and name 
function sendemail($address, $scanreduser) 
{ 
    include('../dbconnect.php'); 
    $info = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE usernum='". $usernum ."' LIMIT 1 ")); 
    $vcard_content = "BEGIN:VCARD\r"; 
    $vcard_content .= "VERSION:3.0\r"; 
    $vcard_content .= "N:".$info[lname].";". $info[fname] .";;;\r"; 
    $vcard_content .= "FN:".$info[fname]." ". $info[lname] ."\r"; 
    $vcard_content .= "ORG:".$info[company].";\r"; 
    $vcard_content .= "TITLE:".$info[title]."\r"; 
    $vcard_content .= "EMAIL;type=INTERNET;type=WORK;type=pref:".$info[email]."\r"; 
    $vcard_content .= "TEL;type=WORK;type=pref:".$info[phone]."\r"; 
    $vcard_content .= "item2.URL;type=pref:".$info[website]."\r"; 
    $vcard_content .= "item2.X-ABLabel:_$!<HomePage>!\$\_\r"; 
    $vcard_content .= "X-ABShowAs:COMPANY\r"; 
    $vcard_content .= "END:VCARD"; 

    $email_subject = "Your vCard from " . $info[fname] . " " . $info[lname]; 
    $fileatt_type = "application/octet-stream"; // File Type 
    $fileatt_name = $info[fname] ."_". $info[lname] .".vcf"; 

    $headers = "From: [email protected]"; 
    $today = date("l, F j, Y, g:i a"); 

    $message = "<br />Simply open the attached vCard file to view/download the information<br />"; 
    $message .= $today." PST<br /><br />"; 
    $message .= $info[name]."<br />"; 

    $data = $vcard_content; 
    $data = chunk_split(base64_encode($data)); 

    $semi_rand = md5(time()); 
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 

    $headers .= "\nMIME-Version: 1.0\n" . 
    "Content-Type: multipart/mixed;\n" . 
    " boundary=\"{$mime_boundary}\""; 

    $message .= "This is a multi-part message in MIME format.\n\n" . 
    "--{$mime_boundary}\n" . 
    "Content-Type:text/html; charset=\"iso-8859-1\"\n" . 
    "Content-Transfer-Encoding: 7bit\n\n" . 
    $message . "\n\n"; 
    $message .= "--{$mime_boundary}\n" . 
    "Content-Type: {$fileatt_type};\n" . 
    " name=\"{$fileatt_name}\"\n" . 
    "Content-Transfer-Encoding: base64\n\n" . 
    $data . "\n\n" . 
    "--{$mime_boundary}--\n"; 

    echo @mail($address, $email_subject, $message, $headers); 
    echo $address; 


} 
+0

新服務器是否有正確配置的SMTP服務器(sendmail,postfix,qmail等)?如果是這樣,請檢查/ var/log/mail *中的maillog ...此外,如果您在電子郵件之前丟失了@,您可能會收到一條有用的錯誤消息,以便與... – Carpetsmoker 2011-03-16 19:49:56

+0

您安裝了哪個郵件服務器VPS? – mario 2011-03-16 19:51:12

回答

1

它可能坐在您的服務器上的某個隊列中。檢查你的php.ini。

只是將它縮小一點,嘗試一個非常簡單的郵件命令

mail("[email protected]", "Subject", "Testing 3, 2, 1...");

在腳本

另外,如果有一個問題,你不會看到它。前面的@禁用顯示錯誤。既然它迴歸真實,我敢打賭它工作得很好。 mail()函數不驗證電子郵件是否被成功發送......只是它被交給別的東西。您的郵箱可能無法正常工作。或者對於Windows,您的SMTP服務器可能設置不正確。

垃圾郵件過濾器中總是存在電子郵件。

+0

好的,所以我試着執行那個簡單的郵件腳本,它仍然沒有發送任何東西......任何想法我應該在我的php.ini文件中尋找......我有點生疏。對不起,我想這是更多的服務器問題比代碼... – Robert 2011-03-16 19:57:24

+0

看看'sendmail_path'和'sendmail_from'。如果在Windows上,請檢查STMP區域。 – Brad 2011-03-16 20:21:07

0

的問題可能是$ usernum沒有設置,使用全局$ usernum或將其傳遞給函數也$ scanreduser從未使用過

+0

哦,對不起'回合...... usernum是實際設置的,當我將代碼複製到剪貼板並忘記更改它時,我正在擺弄 – Robert 2011-03-16 19:56:17

0

很好的選擇是使用的PHPMailer類(HTTP://phpmailer.worxware的.com /)。我使用這個類,它完美的工作。

相關問題