2017-07-15 29 views
0

請幫我解決我的代碼問題,我試圖用這個函數發送郵件,但它沒有發送郵件。如果有人幫助我查看整個代碼庫並更正錯誤,我將不勝感激。謝謝。如何在函數調用中傳遞變量

emailClass.php

<?php 

class email 
{ 
function emailWithAttach($fromaddress, $toAddress, $mailSubject, $mailMessageHead, $mailMessageMain, $mailMessageEnd, $fileName) 
{ 
    $fileatt_name = "Invoice"; 
    $fileatt = $fileName; 
    $fileatt_type = "application/octet-stream"; 
    $email_from = $fromaddress; 
    $email_subject = $mailSubject; 

    $email_message = $mailMessageHead."<br>"; 
    $email_message .= $mailMessageMain."<br>"; 
    $email_message .= $mailMessageEnd; 

    $email_to = $toAddress; 
    $headers = "From: ".$email_from; 

    $file = fopen($fileatt, 'rb'); 
    $data = fread($file, filesize($fileatt)); 
    fclose($file); 

    $semi_rand=md5(time()); 
    $mime_boundary .= "==Multipart_Boundary_x{$semi_rand}x"; 
    $headers .= "MIME-Version:1.0\n". 
    "Content-Type: Multipart/mixed;\n". 
    "boundary=\"{$mime_boundary}\""; 

    $email_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". 
    $email_message .= "\n\n"; 

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

    $email_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"; 

    if(mail($email_to, $email_subject, $email_message, $headers)) 
    { 
     return true; 
    } 

} 
} 


?> 

這是我的模板的index.php

<?php 
include "emailClass.php"; 

$testEmail = new email(); 
$from = '[email protected]'; 
$sendTo = '[email protected]'; 
$subject ='ABS Travels'; 
$bodyHead = 'Welcome to attachment of Email'; 
$bodyMain = 'I love the way php handles email attachment, it is amazing to me'; 
$bodyEnd = 'Thank you'; 
//$filePath = ''; 
$fileName = 'reports.pdf'; 

if($testEmail->emailWithAttach($from, $sendTo, $subject, $bodyHead, $bodyMain, $bodyEnd, $fileName)) 
{ 
    echo 'Email send successful'; 
} 
else 
{ 
    echo 'Email Failed'; 
} 
?> 

我已經更新了我的所做的修正代碼,但郵件沒有發送。請任何建議..它不會顯示除「電子郵件失敗」消息之外的任何錯誤。

+2

對不起,但問題只是要求「我的代碼不起作用,請修復它」顯然被認爲是在這裏脫離主題。你想找一個(付費)程序員爲你做你的工作。我們在這裏提供幫助,但爲此你需要1.願意調試自己,2.告訴我們究竟是什麼問題。 – arkascha

+0

'''$ testEmail-> emailWithAttach()'''的輸出是什麼。 ? –

+0

一個提示:打開或錯誤日誌記錄,從@mail(...)調用中移除該@並啓動監視您的http服務器錯誤日誌文件。它可能會告訴你具體的問題,如果問題在你的代碼中。如果您是在Web環境中使用PHP進行編程,則無法監控該錯誤日誌文件。沒有工作就像在一個黑暗的洞穴與你的眼睛盲折... – arkascha

回答

0

修復錯字,它應該工作!

<?php 
[...] 

$testEmail = new email(); # When you call a new class you need the parenthese 
[...] 
?> 
+0

感謝您的答覆..我已經做到了,但電子郵件失敗的消息仍然存在.. – Koodie

+0

請更新您的問題與您的錯誤 – funilrys