如何制作一个通过电子邮件发送图像(来自用户上传)的提交php?

如何制作一个通过电子邮件发送图像(来自用户上传)的提交php?,php,image,send,mailer,Php,Image,Send,Mailer,我需要帮助生成电子邮件的表单,我会在这里尝试很多,但没有一个匹配我需要的。我有一个表格,我已经从贝尔在线邮件,但这个脚本不允许图像发送。。。所以我修改了一些表单代码,现在我已经有了一个上传表单。现在,我必须添加什么样的函数或php才能将其显示为表单消息中的图像(未附加)。。 这是密码 <?php /* BELLonline PHP MAILER SCRIPT v1.5 Copyright 2006 Gavin Bell

我需要帮助生成电子邮件的表单,我会在这里尝试很多,但没有一个匹配我需要的。我有一个表格,我已经从贝尔在线邮件,但这个脚本不允许图像发送。。。所以我修改了一些表单代码,现在我已经有了一个上传表单。现在,我必须添加什么样的函数或php才能将其显示为表单消息中的图像(未附加)。。 这是密码

        <?php
    /* 
        BELLonline PHP MAILER SCRIPT v1.5
        Copyright 2006 Gavin Bell 
        http://www.bellonline.co.uk 
        gavin@bellonline.co.uk

        Set up an email form on your website within minutes - see readme.txt for installation.
    */

    extract($_POST);

    if (!file_exists("config.php")) 
        {
    $host = $_SERVER[HTTP_HOST ];

$path = pathinfo($_SERVER['PHP_SELF']); $file_path = $path['dirname']; print "<h1>BELLonline PHP mailer script</h1>     <h2>There is a problem with your PHP mailer script installation</h2>    <p>The config.php file seems to be missing!</p>     <p>For this script to work, you need to upload the config.php file that came with the download of the BELLonline <a href=\"http://bellonline.co.uk/downloads/php-mailer-script/\">PHP mailer script</a>.</p>    <p>The file must be in the following directory of your website:</p>     <p>$host<span style=\"font-weight: bold; font-size: 150%;\">$file_path/</span></p>  <p>If you need help installing the script, then feel free to email me at <a href=\"&#x6d;&#x61;&#105;&#108;&#116;&#x6f;&#58;&#x67;&#x61;&#118;&#x69;&#110;&#64;&#98;&#x65;&#x6c;&#x6c;&#x6f;&#110;&#x6c;&#105;&#110;&#101;&#46;&#x63;&#111;&#46;&#x75;&#x6b;\">&#x67;&#x61;&#118;&#x69;&#110;&#64;&#98;&#x65;&#x6c;&#x6c;&#x6f;&#110;&#x6c;&#105;&#110;&#101;&#46;&#x63;&#111;&#46;&#x75;&#x6b;</a></p>"; exit;     } include "config.php";


if ($sendto_email == "changeme@example.com")    { print "<h1>BELLonline PHP mailer script</h1>  <h2>Installation nearly complete!</h2>  <p>Thank you for downloading the <a href=\"http://bellonline.co.uk/downloads/php-mailer-script/\" title=\"free PHP mailer script\">free PHP mailer script</a> from <a href=\"http://www.bellonline.co.uk\">BELLonline web services</a>. </p>    <p>To start using the script, open config.php in a text editor and change the <b>&#36;sendto_email</b> variable to your email address.</p>  <p>If you did not get a config.php file with this script, then go to the <a href=\"http://bellonline.co.uk/downloads/php-mailer-script/\">PHP mailer script page</a> and download the full script.</p>  <p>If you need help installing the script, then feel free to email me at <a href=\"&#x6d;&#x61;&#105;&#108;&#116;&#x6f;&#58;&#x67;&#x61;&#118;&#x69;&#110;&#64;&#98;&#x65;&#x6c;&#x6c;&#x6f;&#110;&#x6c;&#105;&#110;&#101;&#46;&#x63;&#111;&#46;&#x75;&#x6b;\">&#x67;&#x61;&#118;&#x69;&#110;&#64;&#98;&#x65;&#x6c;&#x6c;&#x6f;&#110;&#x6c;&#105;&#110;&#101;&#46;&#x63;&#111;&#46;&#x75;&#x6b;</a></p>"; exit;     }  if (empty ($senders_name))   {   $error = "1";   $info_error .= $lang_noname . "<br>";   } if (empty ($senders_email))   {   $error
= "1";  $info_error .= $lang_noemail . "<br>";      } if (empty ($mail_subject))    {   $error = "1";   $info_error .= $lang_nosubject . "<br>";    } if (empty ($mail_message))    {   $error = "1";   $info_error .= $lang_nomessage . "<br>";    } if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $senders_email))  {   $error = "1";   $info_error .= $lang_invalidemail . "<br>";     } if (empty ($security_code))       {   $error = "1";   $info_error .= $lang_nocode . "<br>";       } elseif ($security_code != $randomness)    {   $error = "1";   $info_error .= $lang_wrongcode . "<br>";    } if ($showlink != "no")    {   $link = "<br><span style=\"font-size: 10px;\">Powered by <a href=\"http://bellonline.co.uk/downloads/php-mailer-script/\" title=\"free PHP mailer script\">BELLonline PHP mailer script</a></span>";    } if ($error == "1")    {   $info_notice = "<span style=\"color: " . $error_colour . "; font-weight: bold;\">" . $lang_error . "</span><br>";       if (empty ($submit))        {       $info_error = "";       $info_notice = $lang_notice;        }   

    function Random()       {       $chars = "ABCDEFGHJKLMNPQRSTUVWZYZ23456789";        srand((double)microtime()*1000000);         $i = 0;         $pass = '' ;        while ($i <= 4)             {           $num = rand() % 32;             $tmp = substr($chars, $num, 1);             $pass = $pass . $tmp;           $i++;           }       return $pass;       }   $random_code = Random();    $mail_message = stripslashes($mail_message);

    print "<form name=\"BELLonline_email\" enctype=\"multipart/form-data\" method=\"post\" style=\"margin: 0;\" action=\"\">   <table  border=\"0\" cellspacing=\"2\" cellpadding=\"2\">
    <tr align=\"$title_align\" valign=\"top\">
      <td colspan=\"2\"><span style=\"$title_css\">$lang_title</span></td>
    </tr>
    <tr align=\"left\" valign=\"top\">
      <td colspan=\"2\">$info_notice$info_error</td>
    </tr>
    <tr valign=\"top\">
      <td align=\"right\">$lang_name</td>
      <td align=\"left\"><input name=\"senders_name\" type=\"text\" class=\"mailform_input\" id=\"senders_name\" style=\"width: $input_width;\" value=\"$senders_name\" maxlength=\"32\"></td>
    </tr>
    <tr valign=\"top\">
      <td width=\"100\" align=\"right\">$lang_youremail</td>
      <td align=\"left\"><input name=\"senders_email\" type=\"text\" class=\"mailform_input\" id=\"senders_email\" style=\"width: $input_width;\" value=\"$senders_email\" maxlength=\"64\"></td>
    </tr>
    <tr valign=\"top\">
      <td width=\"100\" align=\"right\">$lang_subject</td>
      <td align=\"left\"><input name=\"mail_subject\" type=\"text\" class=\"mailform_input\" id=\"mail_subject\" style=\"width: $input_width;\" value=\"$mail_subject\" maxlength=\"64\"></td>
    </tr>
    <tr valign=\"top\">
      <td width=\"100\" align=\"right\">$lang_message</td>
      <td align=\"left\"><textarea name=\"mail_message\" cols=\"36\" rows=\"5\" style=\"width: $input_width;\" class=\"mailform_input\">$mail_message</textarea></td>
    </tr>
    <tr valign=\"top\">
      <td width=\"100\" align=\"right\">$lang_image</td>
      <td align=\"left\"><input name=\"mail_image\" size=\"10\" type=\"file\" class=\"mailform_input\" id=\"mail_image\" value=\"$mail_image\" maxlength=\"64\"></td>
    </tr>
    <tr align=\"left\" valign=\"top\">
      <td width=\"100\">$lang_confirmation</td>
      <td><input name=\"security_code\" type=\"text\" id=\"security_code\" size=\"5\"> 
        &nbsp;&nbsp;&nbsp;&nbsp;<b>$random_code</b></td>
    </tr>
    <tr valign=\"top\">
      <td colspan=\"2\" align=\"right\"><input name=\"randomness\" type=\"hidden\" id=\"randomness\" value=\"$random_code\">
      <input name=\"submit\" type=\"submit\" id=\"submit\" value=\"$lang_submit\" class=\"mailform_button\"></td>
    </tr>   </table> </form>";  } else  {

            if ($checkdomain == "yes")          {       $sender_domain = substr($senders_email, (strpos($senders_email, '@')) +1);      $recipient_domain = substr($sendto_email, (strpos($sendto_email, '@')) +1);         if ($sender_domain == $recipient_domain)            {           print "Sorry, you cannot send messages from this domain ($sender_domain)";          exit;           }               }

            $info_notice = $lang_sent;  $mail_message = stripslashes($mail_message);    $mail_image = $_POST['mail_image'];     $content = $mail_image . $mail_message .    '<p> Oleh ' . $senders_name . ', hubungi ' . $senders_email . ' </p>';  $senders_email = preg_replace("/[^a-zA-Z0-9s.@-_]/", "-", $senders_email);  $from = $senders_email;     $senders_name = preg_replace("/[^a-zA-Z0-9s]/", " ", $senders_name);    $headers = "From: $senders_name <$senders_email> \r\n";     $headers .= "X-Mailer: BELLonline.co.uk PHP mailer \r\n";   $result = sendmail($sendto_email, $mail_subject, $content, $from);


    print "  <table  border=\"0\" cellspacing=\"2\" cellpadding=\"2\">
    <tr align=\"$title_align\" valign=\"top\">
      <td colspan=\"2\"><span style=\"$title_css\">$lang_title</span></td>
    </tr>
    <tr align=\"$title_align\" valign=\"top\">
      <td colspan=\"2\">$info_notice</td>
    </tr>
    <tr valign=\"top\">
      <td width=\"100\" align=\"right\">$lang_name</td>
      <td align=\"left\"><b>$senders_name</b></td>
    </tr>
    <tr valign=\"top\">
      <td width=\"100\" align=\"right\">$lang_youremail</td>
      <td align=\"left\"><b>$senders_email</b></td>
    </tr>
    <tr valign=\"top\">
      <td width=\"100\" align=\"right\">$lang_subject</td>
      <td align=\"left\"><b>$mail_subject</b></td>
    </tr>


      <tr valign=\"top\">
          <td width=\"100\" align=\"right\">$lang_message</td>
          <td align=\"left\"><b>$mail_message</b></td>
        </tr>
      </table>";
        }

    //Simple mail function with HTML header
    function sendmail($sendto_email, $mail_subject, $content, $from) {
        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
        $headers .= 'From: ' . $from . "\r\n";

        $result = mail($sendto_email, $mail_subject, $content, $headers);

        if ($result) return 1;
        else return 0;
    }
    ?>


您可以使用PHP上传或图像上传程序(我目前正在使用)轻松解决问题,并发送电子邮件。正如您提到的,不打算将图像作为附件发送,在PHP Mailer中,您只需设置一条包含图像的html消息。

欢迎使用StackOverflow!我怀疑这里有太多格式不好的代码,对于我们大多数人来说,无法给出一个简洁的答案,而实际上您会发现这个答案很有用。对于“在这200行代码中搜索我的bug”问题,您将进一步缩小范围,仅限于您遇到问题的特定任务。要生成MIME多部分电子邮件吗?关于这个问题有很多疑问。要将文件转换为base64吗?也一样。是否将上载的图像保存到可在电子邮件中引用的路径?这方面有很多文档。告诉我们你遇到的问题。我是一个php初学者,我不知道该怎么做,只是尝试从外包复制粘贴。。。你上面看到的代码是贝尔在线邮件生成的,不是我。。。我不怀疑这是坏代码我认为格式很简单,我没有说它是“坏代码”(可能是),只是它的格式不好。这使得它很难阅读,尤其是在大块的情况下。至于您的问题,请记住StackOverflow是为了帮助您更好地理解代码,以便编写更好的程序。这不仅仅是一个让别人免费为你工作的地方(尽管这种情况经常发生)。我的建议是:弄清楚贝尔邮件程序是做什么的,然后用你想要的额外功能编写你自己的邮件程序。如果有什么东西坏了,隔离坏了的东西,并发布最小的代码来显示错误。嗨,Robyflc,你能直接给出你用来处理和通过电子邮件发送图像的代码吗?我过去做过,但不幸的是,我手头没有做这类事情的代码。我在上面读到,您是PHP编程的初学者,我建议的工具有很好的文档,并且易于实现。即使是一个初学者,你也能在知道的时间内完成,并在这个过程中学到很多东西。