【问题标题】:Upload file send to email Using html and javascript [duplicate]使用html和javascript上传文件发送到电子邮件[重复]
【发布时间】:2016-06-09 06:41:27
【问题描述】:

我有一个用博客设计的工作门户网站。我希望用户上传简历发送到我的电子邮件。这是我的代码。

<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>

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

【问题讨论】:

    标签: javascript php html email blogger


    【解决方案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';
    }
    

    【讨论】:

      猜你喜欢
      • 2013-02-11
      • 2015-09-22
      • 1970-01-01
      • 2015-02-19
      • 1970-01-01
      • 1970-01-01
      • 2016-05-06
      • 1970-01-01
      • 2023-02-01
      相关资源
      最近更新 更多