简体   繁体   English

来自 PHPMailer 的 SMTP 封电子邮件现已迁移至 AWS

[英]SMTP emails from PHPMailer not working now migrated to AWS

I have a large piece of software that was previously hosted on Godaddy, i used the below code to send appointment confirmations to customers:我有一个以前托管在 Godaddy 上的大型软件,我使用以下代码向客户发送预约确认:

 if ($systemToken == $token) {
            if ($permission) { //if the user is an admin.
                require 'PHPMailer-master/PHPMailerAutoload.php';
                $mail = new PHPMailer;
                //$mail->SMTPDebug = 3;                               // Enable verbose debug output
                $mail->isSMTP(); // Set mailer to use SMTP
               $mail->Host = 'localhost';
                $mail->SMTPAuth = false;
                $mail->SMTPAutoTLS = false; 
                $mail->Port = 25; 

                if($branding == 1 || $branding == '1'){
                    $new_username = 'info@XXX1.co.uk';
                    $new_password = 'X';
                }
                else
                {
                    $new_username = 'info@XXX2.co.uk';
                    $new_password = 'X';
                }
                $mail->Username = $new_username; // SMTP username
                $mail->Password = $new_password; // SMTP password
                $mail->setFrom('info@XX.co.uk', 'Your Invoice');
                $mail->addAddress($sendto); // Add a recipient
                $mail->addAttachment($pdf);         // Add attachments
                $mail->isHTML(true); // Set email format to HTML
                $mail->Subject = $subject;
                $mail->Body = "<html><body><p>Hi " . $fname . ",</p><p>We are pleased to confirm your appointment on " . $app . ".</p>

                     <p>Please reply to this email if you need to re-arrange your appointment, or have any questions or queries.</p>

                                                                                </body></html>";
                $mail->AltBody = '';
                if (!$mail->send()) {
                    echo 'Message could not be sent.';
                    echo 'Mailer Error: ' . $mail->ErrorInfo;
                } else {
                   
                    echo '{"text":"Email sent to ' . $sendto . '"}';
                }
            } else {
                echo '{"error":{"text":"Invalid Permissions"}}';
            }
        } else {
            echo '{"error":{"text":"No access"}}';
        }

Due to a huge spike in traffic i have switched over to amazon web services dedicated server, what do i need to install or change to send the emails as i did on Godaddy?由于流量激增,我已切换到 amazon web 服务专用服务器,我需要安装或更改什么才能像在 Godaddy 上那样发送电子邮件? I know that localhost needs to be changed but im not sure whats the best to go with?我知道 localhost 需要更改,但我不确定 go 最好用什么? can i use any hosting packages settings or is there more too it than that我可以使用任何托管包设置还是有更多的设置

First of all you're using an old version of PHPMailer so I suggest you update, and look at using composer.首先,您使用的是旧版本的 PHPMailer,因此我建议您更新并查看使用 composer。

AWS isn't shared hosting, so no mail server is provided, but you can very easily install your own. AWS 不是共享主机,因此不提供邮件服务器,但您可以非常轻松地安装自己的服务器。 All you will usually need is apt install postfix , and select its “inte.net site” option and that will work with your existing script.您通常需要的只是apt install postfix和 select 它的“inte.net 站点”选项,这将与您现有的脚本一起使用。

However, you will then run into a problem with AWS;但是,您随后会遇到 AWS 问题; they don't like you sending email, so you will often find that outbound SMTP is blocked.他们不喜欢你发送 email,所以你会经常发现出站 SMTP 被阻止。 The only real way to work around this is pay for their SES mail service.解决此问题的唯一真正方法是为他们的 SES 邮件服务付费。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM