Nav*_*eed 8 php email smtp email-attachments
我正在使用以下代码成功发送电子邮件.但现在我想附上一个带有电子邮件的文本文件(例如:test.txt).任何的想法?
require_once "Mail.php";
$from = "Usman <from@example.com>";
$to = "Naveed <to@example.com>";
$subject = "subject";
$body = "";
$host = "smtp.gmail.com";
$username = "username";
$password = "password";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory( 'smtp', array('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password ) );
$mail = $smtp->send( $to, $headers, $body );
if ( PEAR::isError($mail) ) {
echo( "<p>" . $mail->getMessage() . "</p>" );
} else {
echo( "<p>Message successfully sent!</p>" );
}
Run Code Online (Sandbox Code Playgroud)
Mae*_*lyn 11
发现此代码是google://pear mail attachment
搜索的第一个命中之一.
include('Mail.php');
include('Mail/mime.php');
$text = 'Text version of email';
$html = '<html><body>HTML version of email</body></html>';
$file = './files/example.zip';
$hdrs = array(
'From' => 'someone@domain.pl',
'To' => 'someone@domain.pl',
'Subject' => 'Test mime message'
);
$mime = new Mail_mime();
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$mime->addAttachment($file,'application/octet-stream');
$body = $mime->get();
$hdrs = $mime->headers($hdrs);
$mail =& Mail::factory('mail', $params);
$mail->send('mail@domain.pl', $hdrs, $body);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
34957 次 |
最近记录: |