2016-06-09 86 views
-1

我有一个在博主中设计的求职门户网站。我希望用户上传恢复发送到我的电子邮件。这是我的代码。上传文件发送至电子邮箱使用html和javascript

<form action="https://examples.webscript.io/attachments/file" 
 
    method="post" enctype="multipart/form-data"> 
 
    <input type="text" name="email" value="[email protected]" 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='[email protected]', 
 
    [email protected], 
 
    subject='Webscript demo: file attachment', 
 
    text='This is an automated email from a Webscript example. '.. 
 
\t \t '(https://www.webscript.io/script/examples/attachments/file)', 
 
    attachments = { request.files.attachment } 
 
} 
 
return "Email sent." 
 
</script>

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

回答

-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 = '[email protected]';     // 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('[email protected]', 'Mailer'); 
$mail->addAddress('[email protected]', 'Joe User');  // Add a recipient 
$mail->addAddress('[email protected]');    // Name is optional 
$mail->addReplyTo('[email protected]', 'Information'); 
$mail->addCC('[email protected]'); 
$mail->addBCC('[email protected]'); 

$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'; 
} 
相关问题