如何将我的电子邮件附件表单连接到php。直接我的电子邮件

时间:2013-10-07 06:29:18

标签: php html

如何将我的电子邮件附件表单连接到php。指导我的电子邮件。

Html: -

  <form id="form" class="blocks" enctype="multipart/form-data" action="js/upload_file.php" method="post">
    <p>
        <label>
            Name:</label>
        <input type="text" class="text" name="name" />
    </p>
    <p>
        <label>
            Address:</label>
        <input type="text" class="text" name="address" />
    </p>
    <p>
        <label>
            Phone:</label>
        <input type="text" class="text" name="phone" />
    </p>
    <p class="area">
        <label>
            Year Exp:</label>
        <input type="text" class="text" name="exp" />
    </p>

                      <p class="area">
        <label for="file">
            Upload ur CV:</label>
        <input type="file" name="attachment">
    </p>
    <p>
        <label>
            &nbsp;</label>
        <input type="submit" class="btn" value="Submit" />
    </p>
 </form>

    <div class="right">
        <img src="images/Careers.png" width="350" height="334">
    </div>

    </div>
            </div>

    </div>

如何将我的电子邮件附件表单连接到php。直接我的电子邮件 如何将我的电子邮件附件表单连接到php。直接我的电子邮件 如何将我的电子邮件附件表单连接到php。指导我的电子邮件。

PHP: -

 <?php
if (isset($_REQUEST['email']))
{
  $domain='www.example.com';
  $from='www.example.com';
  $name = $_REQUEST['name1'] ;
  $add = $_REQUEST['add'] ;
  $phone = $_REQUEST['phone'] ;
  $exp = $_REQUEST['exp'] ;
  $attachment = $_REQUEST['attachment'] ;
    $subject = 'Massage recieved from Pearl : '.$domain.'';
    $body = $email.'

    The person that contacted you is : '.$name.'

    |------------------Full Details--------------------|

   Name:            '.$name.'
     Address:          '.$add.'
     Phone:          '.$phone.'
     Experience:         '.$exp.'
     Attachment:         '.$attachment.'

    |--------------------End---------------------------|'; 
  echo ("<SCRIPT LANGUAGE='JavaScript'>
    window.alert('Thank you for your feedback. We will contact you shortly')
    window.location.href='http://www.pearlgroup.asia';
    </SCRIPT>");  

mail("info@example.com",$from, $subject, $body);

// Check, if message sent to your email 
// display message "We've recived your information"

}
else
{
echo "Try again";
}
?>`

2 个答案:

答案 0 :(得分:0)

如果我理解你的问题:http://webcheatsheet.com/PHP/send_email_text_html_attachment.php

希望它有所帮助。

答案 1 :(得分:0)

基于使用pear库的这篇文章(http://www.html-form-guide.com/email-form/php-email-form-attachment.html),在获得附件并进行处理之后,然后您可以使用邮件库发送电子邮件...

$message = new Mail_mime(); 
$message->setTXTBody($text); 
$message->addAttachment($path_of_uploaded_file); 
$body = $message->get(); 
$extraheaders = array("From"=>$from, "Subject"=>$subject,"Reply-To"=>$visitor_email); 
$headers = $message->headers($extraheaders); 
$mail = Mail::factory("mail"); 
$mail->send($to, $headers, $body);

如果你想使用swift(http://swiftmailer.org/),逻辑仍然相同......

$message = Swift_Message::newInstance('Subjct', 'Body message');
$message->attach(Swift_Attachment::fromPath('/path/to/file'));