2014-03-31 71 views
0

這是我第一次使用PHP,並且在執行所有郵件形式時遇到困難,我似乎無法完成此工作。下面是我的代碼,如果有人能夠在調試方面指向正確的方向,我會非常感激。PHP郵件腳本問題

<?php 

    $job_number   = $_POST['job_number']; 
    $completion_time = $_POST['completion_time']; 
    $email    = $_POST['email']; 

    $formcontent  = "From: $email \n \n Job Number: $job_number \n \n Completion Time: $completion_time \n"; 

    $recipient   = "[email protected]"; 
    $subject   = "Repeat Order"; 
    $mailheader   = "From: $email \r\n"; 

    mail(
      $recipient, 
      $subject, 
      $formcontent, 
      $mailheader 
    ) 
    or die(
     " 
      Error! 
     " 
    ); 

    echo( " 
       <div style='font-size:24px; margin-top: 100px; text-align: center;'> 
        Thank You! 
      " 
      . " - " . 
      "  <a href='home.html' style='color: #1ca03e;'> 
         Return Home 
        </a> 
       </div> 
      " 
    ); 

?> 

謝謝 卡梅倫

編輯:一些更多的信息,該服務器支持PHP腳本的郵件,因爲它之前(根據朋友我建立這個對),錯誤有一個在那裏我已經有內部測試是郵件正在發送,但沒有任何'$ formcontent'內容...只有標題(又名:From :,工作號碼:,完成時間:)

編輯編輯:如果這裏有幫助的話,那就是一臺登臺服務器我現在已經開始使用了(不要因爲糟糕的網頁設計而討厭我......這是一項正在進行的工作)http://temp.fullaf.com/cameron/rak/repeat.html

+2

你會得到什麼錯誤? –

+0

你有一些郵件服務器配置?一些SMTP? – Uriziel

+0

用這個信息編輯原文,抱歉沒有包括它。 –

回答

1

您可以在其網站上得到swiftmailer包在這裏 - >http://swiftmailer.org/

require_once 'swiftmailer/lib/swift_required.php'; 

function new_mail($subject, $content, $recipients, $from) 
{ 
    // Create the message 
    $message = Swift_Message::newInstance(); 

    // Give the message a subject 
    $message->setSubject($subject); 

    // Set the From address with an associative array 
    $message->setFrom($from); 

    // Set the To addresses with an associative array 
    $message->setTo($recipients); 

    // Give it a body 
    $message->setBody($content); 

    $transport = Swift_MailTransport::newInstance(); 
    $mailer = Swift_Mailer::newInstance($transport); 
    $result = $mailer->send($message); 

} 

$job_number   = $_POST['job_number']; 
$completion_time = $_POST['completion_time']; 
$email    = $_POST['email']; 

$message = "From: $email \n \n Job Number: $job_number \n \n Completion Time: $completion_time \n"; 

$recipients   = array('[email protected]' => 'Your name of choice'); 
$subject   = "Repeat Order"; 
$from    = array($email => 'Name of choice.'); 

new_mail($subject, $message, $recipients, $from); 

我目前沒有在那裏我可以訪問FTP服務器來測試這個特定的片斷,但嘗試一下位置。如果有任何問題,請告訴我。

+0

我會現在在我的測試,謝謝:) –

+0

@CameronGuthrie你試過了嗎? – Rimble

+0

是的,只是在等待我的朋友的回覆,告訴他是否真的收到了任何東西(我推送了兩個版本的服務器......一個與這個和一個沒有)。如果它有效,將會標記爲已回答:) –

1

您的代碼正在工作併發送電子郵件沒有任何問題。

  1. 檢查您的電子郵件垃圾郵件框。有時候,電子郵件會轉到垃圾郵件框。
  2. 您正在使用此「[email protected]」電子郵件地址作爲收件人電子郵件地址。因此,請勿將發件人電子郵件地址使用同一電子郵件地址。使用其他電子郵件地址作爲發件人電子郵
  3. 請確保您的電子郵件地址「[email protected]」在從其他電子郵件帳戶(例如yahoo和gmail)發送電子郵件時正確接收電子郵件。
  4. 請確保您已在服務器中正確設置郵件服務器。
+0

我會做更多的測試,現在給我的朋友打電話來檢查他的垃圾郵件文件夾。謝謝,非常感謝。 (我會標記爲回答,如果它的工作):) –