我的代碼 -幫助在PHP中使用郵件功能
$from = "From:Company\n\r";
$mesg = include('mail.html');
function mail($u,'hey',$mesg);
發送郵件基本上,我想發郵件,在該消息需要是mail.html。
help ...需要將消息發送至$u
。
我的代碼 -幫助在PHP中使用郵件功能
$from = "From:Company\n\r";
$mesg = include('mail.html');
function mail($u,'hey',$mesg);
發送郵件基本上,我想發郵件,在該消息需要是mail.html。
help ...需要將消息發送至$u
。
下面是一個使用Swift Mailer當例子的你如何能做到這一點(從手冊中的實例組成):
<?php
require_once 'lib/swift_required.php';
//Create the message
$message = Swift_Message::newInstance()
//Give the message a subject
->setSubject('Your subject')
//Set the From address with an associative array
->setFrom(array('[email protected]' => 'Your Name'))
//Set the To addresses with an associative array
->setTo(array('[email protected]' => 'Recipient\'s name'))
//Set CC
->setCc('[email protected]')
//Give it a body
->setBody(file_get_contents('mail.html'))
;
//Create the Mailer
$mailer = Swift_Mailer::newInstance(Swift_MailTransport::newInstance());
//Send the message
$result = $mailer->send($message);
@Czechnology這太酷了。謝謝...你能告訴我如何使用$ u而不是收件人的電子郵件。 $ u是註冊時的用戶名。謝謝 – sarthak 2011-03-14 18:59:29
@Czechnology另外,我是否需要只包含庫中所有文件中的一個文件? – sarthak 2011-03-14 19:01:13
@sarthak,你不能發送電子郵件到用戶名,你需要一個電子郵件地址。如果你有用戶的電子郵件地址和他的名字,你可以使用' - > setTo(array('[email protected]'=>'Username'))''。 – Czechnology 2011-03-14 19:01:34
不要在郵件的前面使用function
,只是做
mail($emailto, $subject, file_get_contents('mail.html'), $headers);
這不會起作用,因爲include()
包括文件和評估板(解釋的內容),你正在試圖使它像一個函數返回一個不是的值。
您需要做的是使用file_get_contents()
或simillar功能將文件內容讀入變量,然後將其用作消息正文。
我建議你使用PHPMailer類,它真的會給你很多設施和功能,而且下載包含的例子,你將需要包括類文件,然後使用它的免費。如需更多資料go to this link
也是我需要的郵件被抄送到[email protected] 。謝謝。 – sarthak 2011-03-14 18:50:39
我不明白你的問題。你是否重新定義郵件問題? *在旁註中,我建議使用[Swift Mailer](http://swiftmailer.org/)而不是簡單的php'mail'函數。 – Czechnology 2011-03-14 18:52:13
你甚至沒有打擾搜索PHP郵件的權利?所有「相關」主題都顯示在正確的答案上。 – Jakub 2011-03-14 18:52:39