Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
来自提供地址的PHP电子邮件_Php_Email_Email Attachments - Fatal编程技术网

来自提供地址的PHP电子邮件

来自提供地址的PHP电子邮件,php,email,email-attachments,Php,Email,Email Attachments,我有这个PHP脚本,我没有太多的经验,但我提供了一封电子邮件,我想发送的电子邮件与该电子邮件地址,它现在使用我的网络主机帐户的电子邮件地址。。。我必须改变什么 <?PHP $ai_to = urldecode($_GET['to']); $ai_from = urldecode($_GET['fr']); $ai_su = urldecode($_GET['su']); $ai_bo = str_replace("CRLF","\n", urldecode($_GET

我有这个PHP脚本,我没有太多的经验,但我提供了一封电子邮件,我想发送的电子邮件与该电子邮件地址,它现在使用我的网络主机帐户的电子邮件地址。。。我必须改变什么

<?PHP

$ai_to    = urldecode($_GET['to']);
$ai_from  = urldecode($_GET['fr']);
$ai_su    = urldecode($_GET['su']);
$ai_bo    = str_replace("CRLF","\n", urldecode($_GET['bo']));
$ai_fname = urldecode($_GET['fi']);
$ai_fpath = $ai_fname;

$header  = "From: " . 'aiapis mail svc:' . " <" . $ai_from . ">\r\n";
$header .= "Reply-To: " . $ai_from . "\r\n";

if ($ai_fname != '')
{
$data = file_get_contents('php://input');
if (file_put_contents($ai_fpath, $data) === FALSE) die("Upload failed, sen cancelled.");
   $file_size = filesize($ai_fpath);

   if ($file_size > 10485760) die("> 10MB. Send cancelled.");


   $emtemp = 'emailtemp.log';
   $current = file_get_contents($emtemp);
   $current .= gmdate("Y-m-d\TH:i:s") . ", " . $ai_fname . ", " . round($file_size/1048576, 3) . "MB\n";
   file_put_contents($emtemp, $current);   

   $handle = fopen($ai_fpath, "r");
   $content = fread($handle, $file_size);
   fclose($handle);
   $content = chunk_split(base64_encode($content));

   $uid = md5(uniqid(time()));

   $header .= "MIME-Version: 1.0\r\n";
   $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
   $header .= "This is a multi-part message in MIME format.\r\n";
   $header .= "--".$uid."\r\n";
   $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
   $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
   $header .= $ai_bo."\r\n\r\n";
   $header .= "--".$uid."\r\n";
   $header .= "Content-Type: application/octet-stream; name=\"".$ai_fname."\"\r\n";
   $header .= "Content-Transfer-Encoding: base64\r\n";
   $header .= "Content-Disposition: attachment; filename=\"".$ai_fname."\"\r\n\r\n";
   $header .= $content."\r\n\r\n";
   $header .= "--".$uid."--";

   $sent = mail($ai_to, $ai_su, "", $header);
}
else $sent = mail($ai_to, $ai_su, $ai_bo, $header);

if ($sent)
{
   if ($ai_fname != '')
   {
      unlink($ai_fpath);
      echo "Email+attachment sent.";
   }
   else echo "Email sent.";
}
else echo "Mail server rejected email.";

?>

邮件的发件人设置在以下行:

$header  = "From: " . 'aiapis mail svc:' . " <" . $ai_from . ">\r\n";
变量$ai_from是从名为fr的$_GET变量设置的,它来自URL,如下所示:http://www.google.com?fr=myemail@域.net&到=touraddress@domain2.net

这个剧本过去有用吗

如果您不熟悉30多年的电子邮件RFC,请不要使用

改用图书馆

这两个很受欢迎:和。我更喜欢Swift Mailer,但两者都成功使用。我过去也使用邮件,因为我有多年使用Delphi和其他语言处理邮件的经验,所以我知道其中的怪癖

如果您想使用邮件,请注意,如果您在某些情况下没有正确使用邮件,您的电子邮件在有或没有回跳的情况下都无法发送,因此您可能不知道邮件已失败。此外,随邮件发送的电子邮件有时更容易被发送到垃圾邮件文件夹

在PHP中以简单的方式查看和正确发送邮件


顺便说一句,我与他们无关。

其他参数在我看来,发件人和回复收件人的标题设置正确。我认为您的web托管提供商可能会在邮件服务器中覆盖这些内容,而邮件转发通常是一种错误配置。最好也向他们核实一下。我在过去见过这样的例子。我很幸运,在为PHPMailer的首席开发人员andyprovost工作时,我编写了PHPMailer的一小部分代码。这是一个非常灵活和强大的PHP邮件库:我刚刚测试了这个脚本,它确实可以工作,但它总是从webhost电子邮件地址发送。我应该更改您给出的第一行代码吗?顺便说一下,我使用000.webhost.com。我查看了WebHostPHP配置,它说:sendmail\u from=no value sendmail\u path=/usr/local/bin/phpsendmail@user2012141当你使用Swift-Mailer时,你使用了setFrom方法,它被你的主机过度使用了?如果是这种情况,而不是使用sendmail,请使用SMTP服务器,这将起作用。见: