我尝试在用户点击注册页面上的提交按钮后向管理员发送电子邮件。下面给出的代码工作正常,我得到了管理员电子邮件地址的所有详细信息。我被困在两个地方:
$receiver = "admin@mywebsite.com,superadmin@mywebsite.com";
,但它不起作用。邮件不会被发送。需要知道如何将此电子邮件发送给两个不同的人。$panph1
变量返回服务器上的文件名(本例中为1467896354.jpg)。它会在电子邮件正文中显示文件名以及所有其他数据。此文件存储在/pancard/1467896354.jpg - 我应该做些什么更改才能通过此电子邮件附上实际文件。由于
$subject = "New registration from $name ";
$receiver = "admin@mywebsite.com";
$prod_id1=$rowcc['prod_id'];
$mobile1=$rowcc['mobile'];
$reg=$rowcc['reg_date'];
$ip1=$rowcc['ip'];
$panno1=$rowcc['pan_no'];
$panph1=$rowcc['pan_photo'];
$message = "
<html>
<body>
<table>
<tr>
<td>Product ID</td>
<td>:</td>
<td>$prod_id1</td>
</tr>
<tr>
<td>Name</td>
<td>:</td>
<td>$name</td>
</tr>
<tr>
<td>Email Address</td>
<td>:</td>
<td>$to</td>
</tr>
<tr>
<td>Mobile</td>
<td>:</td>
<td>$mobile1</td>
</tr>
<tr>
<td>Registration Date</td>
<td>:</td>
<td>$reg</td>
</tr>
<tr>
<td>IP Address</td>
<td>:</td>
<td>$ip1</td>
</tr>
<tr>
<td>Pan Card Number</td>
<td>:</td>
<td>$panno1</td>
</tr>
<tr>
<td>Pan Card Photo</td>
<td>:</td>
<td>$panph1</td>
</tr>
</table>
</body>
</html>
";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From:'.$from."\r\n"
.'Reply-To: $receiver'."\r\n";
mail($receiver,$subject, $message, $headers);
答案 0 :(得分:1)
为什么不使用PhpMailer?
许多PHP开发人员在其代码中使用电子邮件。唯一的PHP功能 支持这个是mail()函数。但事实并非如此 为使用流行功能提供任何帮助 基于HTML的电子邮件和附件。
以下是使用PhpMailer的示例:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtpserver.com'; // Specify main SMTP server. If you dont have one us GMAL or mandrill
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user@youremail.com'; // SMTP username
$mail->Password = 'pass'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('from@youremail.com', 'Mailer');
$mail->addAddress('joe@youremail.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen@youremail.com'); // Name is optional
$mail->addReplyTo('info@youremail.com', 'Information');
$mail->addCC('cc@youremail.com');
$mail->addBCC('bcc@youremail.com');
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}