简体   繁体   中英

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:

 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? I know that localhost needs to be changed but im not sure whats the best to go with? 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.

AWS isn't shared hosting, so no mail server is provided, but you can very easily install your own. All you will usually need is apt install postfix , and select its “inte.net site” option and that will work with your existing script.

However, you will then run into a problem with AWS; they don't like you sending email, so you will often find that outbound SMTP is blocked. The only real way to work around this is pay for their SES mail service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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