【问题标题】:php send a file attachment inbuild script [duplicate]php在构建脚本中发送文件附件[重复]
【发布时间】:2012-10-04 18:25:08
【问题描述】:

可能重复:
How to send email with attachment using PHP?

你好,我是 php 新手,请告诉我是否有任何脚本或链接(用于发送带有文件多个附件的邮件的 php 脚本)以及 html 表单,以及如何连接此表单或任何内置脚本,以便我可以上传到我的服务器。 我已经尝试了很多方法,方法是处理代码并粘贴它们并更改路径,但仍然会出现很多错误,所以如果有内置脚本可以轻松上传到我的服务器,请告诉我

<?php
if($_GET['name']== '' || $_GET['email']=='' || $_GET['email']=='' || $_GET['Message']=='' )
{
?>

<form action="check3.php" method="get" name="frmPhone"> 
<fieldset> 
<legend style="color:#000">Contact    </legend>  
<table width="100%">
<tr>
<td width="29%">
<label for="name"     <?php     if(isset($_GET['Submit']) && $_GET['name']=='') echo "style='color:red'";    ?>>Name*    </label>     </td>    <td width="71%">
<input id="name" name="name" type="text" style="width:50%" value="    <?php echo $_GET['name'];    ?>"/>    </td>    </tr>    <tr>    <td>

<label for=" email"     <?php     if(isset($_GET['Submit']) && $_GET['email']=='') echo "style='color:red'";    ?>>Email*    </label>     </td>    <td>
<input id="email" name="email" type="text" style="width:50%" value="    <?php echo $_GET['email'];    ?>"/>     </td>    </tr>
</table>
</fieldset> 
<fieldset> 
<legend style="color:#000">Inquiry    </legend>  
<table width="100%">
  <tr>    <td width="41%" valign="top">

    <label for="Message"     <?php     if(isset($_GET['Submit']) && $_GET['Message']=='') echo "style='color:red'";    ?>>Message*</label>     </td>    <td width="59%">    <textarea name="Message" rows="5" style="width:90%" id="Message">    <?php echo $_GET['Message'];    ?>    </textarea> </td><div align="center">Photo
     <input name="photo" type="file" size="35" />
    </div></td>   
  </tr>
  <tr>

     <input name="Submit" type="submit" value="Submit" />
</form>    </td>    </td>




</form>

  </tr>

<?php
 }
else
{
$to      = 'abhi326@gmail.com';
$subject = 'Customer Information';
$message = '
Name: '.$_GET['name'].'
Email Address: '.$_GET['email'].'
Message: '.$_GET['Message'];

$headers = 'From:'.$_GET['email'];

mail($to, $subject, $message, $headers);

$connection=mysql_connect("db2173.perfora.net", "dbo311409166", "malani2002") or die(mysql_error());
 $query = mysql_query("INSERT INTO  `feedback` (  `name` ,  `email` , `Message` ,  `photo` ) VALUES ('".$_GET['name']."',  '".$_GET['email']."', '".$_GET['Message']."')");
define ("MAX_SIZE","75"); 
if(isset($_FILES['photo']['name']) && $_FILES['photo']['name']<>"")    {
$typ = $_FILES['photo']['type'];
    if($typ == "image/g    if" || $typ == "image/png" || $typ == "image/jpeg" || $typ == "image/pg    if" || $typ == "image/ppng" || $typ =="image/JPEG")
    {
    $uploaddir = "contacts/";
    $uploadimages = $uploaddir.basename($_FILES['photo']['name']);
        if(move_uploaded_file($_FILES['photo']['tmp_name'], $uploadimages))      {
        echo "File successfully copied";
        $sql="INSERT INTO contacts (Photo, Beschrijving)
        VALUES ('$uploadimages',
                            '$_POST[images]')";
            if (!mysql_query($sql,$con))    {
            die('Error: ' . mysql_error());
            mysql_close($con);
             }
         }
        else    {echo "Copy unsuccessful";     }
     }
    else    { 
    echo "Incorrect file type";
     }
 }
else    {
echo "No file selected";
 }
echo "Thank you! ";
 }
?>

感谢和问候 阿比

【问题讨论】:

    标签: php email-attachments


    【解决方案1】:

    您要查找的脚本是phpMailer

    此脚本可以下载并轻松添加到您的 PHP 程序中。它使从 PHP 发送电子邮件变得非常容易,包括添加附件。

    希望对您有所帮助。

    【讨论】:

    • 我个人的偏好是 swiftmailer.org 但无论哪种方式,phpMailer 和 SwiftMailer 都可以胜任。
    • @bumperbox:您可以将其添加为重复问题的答案:stackoverflow.com/questions/2027069/…
    猜你喜欢
    • 2012-09-09
    • 2010-10-09
    • 2020-01-04
    • 2016-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-23
    相关资源
    最近更新 更多