Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.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
如何将附加文件添加到我的在线emailer PHP?_Php - Fatal编程技术网

如何将附加文件添加到我的在线emailer PHP?

如何将附加文件添加到我的在线emailer PHP?,php,Php,我希望你能帮我解决我的问题,因为我的网站真的需要它。 如何添加将文件附加到我用PHP编写的在线电子邮件的可能性?:) 下面是我想添加到的代码: <?php session_start(); if( isset($_POST['submit'])) { if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) )

我希望你能帮我解决我的问题,因为我的网站真的需要它。 如何添加将文件附加到我用PHP编写的在线电子邮件的可能性?:)

下面是我想添加到的代码:

<?php 
session_start();

if( isset($_POST['submit'])) 
{
     if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) 
       {  
       $to=$_POST["to"];
       $from=$_POST["from"];
       $name=$_POST["name"];
       $subject=$_POST["subject"];
       $message=$_POST["message"];
       $message=$message."\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
       $head="From: ".$from."\r\n".'Reply-To: '.$From."\r\n";
       $her=$head.' < '.$from.' >';
       $techomag=mail($to, $subject, $message, $her);
       echo "Your Message Has been send successfully...:)..";
           unset($_SESSION['security_code']);
      echo( '<a href="mysite.com/index.php">Click here to send another email</a>' );
      } 
      else 
      {

        echo 'Sorry, you have provided an invalid captcha security code :(...';
        echo( '<a href="mysite.com/index.php">Click here to Go back and try once more</a>' );
      }

} 
else 
{
?>
<?php
?>


<div style="height:10px; clear:both"></div>

<form action="index.php" method="post">
   <table border="1"><tbody>
   <tr><td>To Email :</td><td><input name="to" type="text" /></td></tr>
   <tr><td>From Email :</td><td><input name="from" type="text" /></td></tr>
   <tr><td>From Name :</td><td><input name="name" type="text" /></td></tr>
   <tr><td>Subject :</td><td><input name="subject" type="text" /></td></tr>
   <tr><td>Message :</td><td><textarea cols="30" rows="10" name="message"></textarea></td></tr>
   <tr><td><img src="CaptchaSecurityImages.php?width=100&height=40&characters=5" /><br />
   <label for="security_code">Security Code: </label><input id="security_code" name="security_code" type="text" />
   <input type="submit" name="submit" value="Send Email!" /></td></tr>
   </tbody></table>
</form>

<?php

}

?>

电邮:
通过电子邮件:
发件人姓名:
主题:
信息:

安全代码:
非常适合使用PHP签出类发送复杂的电子邮件

使用PHPMailer中的功能发送复杂的电子邮件(例如带有附件)要容易得多。

可能会重复
<?php
  $filename = "form.txt"; //attach filename
  $to = "abc@mail.ru"; //To
  $from = "def@gmail.com"; //From
  $subject = "Test"; //Subj
  $message = "Текстовое сообщение"; //Message
  $boundary = "---"; //Delimitter
  /* Headers */
  $headers = "From: $from\nReply-To: $from\n";
  $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"";
  $body = "--$boundary\n";
  /* Text message */
  $body .= "Content-type: text/html; charset='utf-8'\n";
  $body .= "Content-Transfer-Encoding: quoted-printablenn";
  $body .= "Content-Disposition: attachment; filename==?utf-8?B?".base64_encode($filename)."?=\n\n";
  $body .= $message."\n";
  $body .= "--$boundary\n";
  $file = fopen($filename, "r"); //Открываем файл
  $text = fread($file, filesize($filename)); //Считываем весь файл
  fclose($file); //Закрываем файл
  /* ADD attach */
  $body .= "Content-Type: application/octet-stream; name==?utf-8?B?".base64_encode($filename)."?=\n"; 
  $body .= "Content-Transfer-Encoding: base64\n";
  $body .= "Content-Disposition: attachment; filename==?utf-8?B?".base64_encode($filename)."?=\n\n";
  $body .= chunk_split(base64_encode($text))."\n";
  $body .= "--".$boundary ."--\n";
  mail($to, $subject, $body, $headers); //SEND
?>