1

谁能帮我编写一个代码,该代码可以一次发送带有两个附件的邮件,这些附件已经在服务器上,并且链接路径保存在数据库(MySql)中?

为了机制

至:

从:

主题:

信息:

附件复选框

我只是一个初学者我只知道如何发送邮件我们发出像贝娄这样的附件

<?php 
$errors = '';
$myemail = 'admin@mydomain.net'
if(empty($_POST['name'])  || 
   empty($_POST['email']) || 
   empty($_POST['message']))
{
    $errors .= "\n Error: all fields are required";
}

$name = $_POST['name']; 
$email_address = $_POST['email']; 
$message = $_POST['message']; 

if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", 
$email_address))
{
    $errors .= "\n Error: Invalid email address";
}

if( empty($errors))
{
    $to = $myemail; 
    $email_subject = "New Mail From: $name";
    $email_body = "$message"; 

    $headers = "From: $myemail\n"; 
    $headers .= "Reply-To: $email_address";

    mail($to,$email_subject,$email_body,$headers);
    //redirect to the 'thank you' page
    header('Location: thank-you.html');
} 

?>
4

1 回答 1

0

你应该看看这个页面:http ://webcheatsheet.com/PHP/send_email_text_html_attachment.php

或者,如果您的服务器支持 PEAR,那么您应该使用带有 Mail_Mime 的 PEAR Mail,这是一个比上述更清洁的解决方案。

<?php

include 'Mail.php';
include 'Mail/mime.php' ;

$text = 'Text version of email';
$html = '<html><body>HTML version of email</body></html>';
$file = '/home/richard/example.php';
$crlf = "\n";
$hdrs = array(
          'From'    => 'you@yourdomain.com',
          'Subject' => 'Test mime message'
          );

$mime = new Mail_mime(array('eol' => $crlf));

$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$mime->addAttachment($file, 'text/plain');

$body = $mime->get();
$hdrs = $mime->headers($hdrs);

$mail =& Mail::factory('mail');
$mail->send('postmaster@localhost', $hdrs, $body);

?>
于 2013-06-13T11:58:20.190 回答