上传文件发送到电子邮件使用html和javascript

时间:2016-06-09 06:41:27

标签: javascript php html email blogger

我有一个在博客中设计的职位门户网站。我希望用户上传简历发送到我的电子邮箱。这是我的代码。



<form action="https://examples.webscript.io/attachments/file"
    method="post" enctype="multipart/form-data">
    <input type="text" name="email" value="rajkumar23@gmail.com" style="display:none;"/>
   
    <input type="file" name="attachment" />
    <button type="submit">Upload</button>
</form>
 
<script type="text/javascript">
local SERVER = '<SMTP SERVER>'
local USERNAME = '<SMTP USERNAME>'
local PASSWORD = '<SMTP PASSWORD>'
 
email.send {
    server=SERVER, username=USERNAME, password=PASSWORD,
    from='hello@webscript.io',
    to=rajkumar23@gmail.com,
    subject='Webscript demo: file attachment',
    text='This is an automated email from a Webscript example. '..
		'(https://www.webscript.io/script/examples/attachments/file)',
    attachments = { request.files.attachment }
}
return "Email sent."
</script>
&#13;
&#13;
&#13;

发送文件后,显示500内部服务器错误。如何解决这个问题。有没有使用PHP的代码。我想用html和javascript设计文件。在博客中,php脚本不支持。

1 个答案:

答案 0 :(得分:-1)

使用波纹管维护的库:

https://github.com/PHPMailer/PHPMailer

并且代码将是

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'user@example.com';                 // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
$mail->addAddress('ellen@example.com');               // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}