duanhunlou7051 2015-06-17 22:02
浏览 22

具有共享主机的PHPMailer(SMTP传输)

I have looked and looked for an answer to this and cannot find anything so If this already has an answer please let me know.

I am using PHPMailer and using SMTP to send emails with files attached.

Here is my Code:

                            <?php

                                /**
                                 * SMTP Server Using Yahoo To Upload Files And Submit, Port 465 Using SSL
                                 */
                                 require_once('PHPMailer/PHPMailerAutoload.php');
                                define('GUSER', '****@yahoo.com'); // Yahoo username
                                define('GPWD', '*****'); // Yahoo password

                                $msg = '';

                                if (array_key_exists('userfile', $_FILES)) {
                                    // First handle the upload
                                    // Don't trust provided filename - same goes for MIME types
                                    // See http://php.net/manual/en/features.file-upload.php#114004 for more thorough upload validation
                                    $uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['userfile']['name']));
                                    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
                                        // Upload handled successfully
                                        // Now create a message
                                        // This should be somewhere in your include_path
                                    $mail = new PHPMailer();  // create a new object
                                    $mail->IsSMTP(); // enable SMTP
                                    $mail->SMTPDebug = 4;  // debugging: 1 = errors and messages, 2 = messages only
                                    $mail->SMTPAuth = true;  // authentication enabled
                                    $mail->SMTPSecure = 'ssl';
                                    $mail->Host = 'smtp.mail.yahoo.com';
                                    $mail->Port = 465;
                                    $mail->Username = GUSER;  
                                    $mail->Password = GPWD;           
                                    $mail->setFrom('****@yahoo.com', 'Sent File');
                                    $mail->addAddress('****@****.com');
                                    $mail->Subject = 'Test File';
                                    $mail->msgHTML("My message body");
                                    // Attach the uploaded file
                                    $mail->addAttachment($uploadfile, $_FILES['userfile']['name']);
                                    if (!$mail->send()) {
                                        $msg = "Mailer Error: " . $mail->ErrorInfo;
                                            } else {
                                                    $msg = "Message sent!";
                                                    }
                                    } else {
                                            $msg = 'Failed to move file to ' . $uploadfile;
                                            }
                                    }

                            ?>

                                <?php if (empty($msg)) { ?>
                                    <form method="post" enctype="multipart/form-data">
                                        <input type="hidden" name="MAX_FILE_SIZE" value="100000"> Send this file: <input name="userfile" type="file">
                                        <input type="submit" value="Send File">
                                    </form>
                                <?php } else {
                                    echo $msg;
                                } ?>

When I Use This on my local lamp server it works perfectly, However when I use it on my Yahoo Hosting Server, I get this error: SMTP ERROR: Failed to connect to server: Permission denied (13)

Looking into what that error represents, It sounds like the problem and solution has to do with the httpd_can_sendmail & httpd_can_network_connect Settings. It looks like they need to be activated. Source: http://gistpages.com/2013/09/14/phpmailer_smtp_error_failed_to_connect_to_server_permission_denied_13_fix

My problem is that with Yahoo, I cannot access a terminal to change these settings. Does anyone know of any other way to change these settings without having access to a linux terminal of the hosting server?

Thanks P.S I would not recommend using yahoo as a website hosting provider EVER to anyone!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
    • ¥50 需求一个up主付费课程
    • ¥20 模型在y分布之外的数据上预测能力不好如何解决