简体   繁体   中英

Send email from GoDaddy Server using PHP or PHPMailer

I want to enable my website users to send an email. I use PHP and my host is GoDaddy. I assume that PHPMailer is the best option. I think my problem is trying to connect to GoDaddy's PHPMailer. Should I use another PHPMailer?

My code is based on an example on your site which is supposed to work. It appears that the lines: require_once "PHPMailerAutoload.php"; $mail = new PHPMailer; //PHPMailer Object prevent the subsequent code from working. Please help.

<?php
    if(isset($_POST['send'])){
        echo "Sending";
        require_once "PHPMailerAutoload.php";
        $mail = new PHPMailer; //PHPMailer Object
        $mail->setFrom('sender@example.com', 'Rob');
       // $mail->addAddress("my godaddy webmail"); //Recipient name is optional
       echo "still Sending";
       $mail->addAddress("recipient@example.com"); //Recipient name is optional
        //Send HTML or Plain Text email
        $mail->isHTML(true);
        $mail->Subject = "Email Test";
        $mail->Body = "<i>This is a text</i>";
        $mail->AltBody = "This is the plain text version of the email content";
        if(!$mail->send()) {
            echo "Mailer Error: " . $mail->ErrorInfo;
        } else {
            echo "Message has been sent successfully";
        }        
    }`enter code here`
?>
<form  method="post">
    <input type="submit" name="send" value="Send">
</form>

Pretty much all virtual hosting servers are banned from sending mail by being placed on an email blacklist . As you might imagine, this is to prevent spammers from simply firing up a new virtual server and sending gobs of spam mail. It's a necessary protection for the inte.net at large.

It's important to realize that the PHP mail() function just returns TRUE if your local server accepted the mail message for outgoing delivery. This just means that the local software running on your server told PHP it would try to send the email. This in NO WAY guarantees that the mail will look legitimate to all the mail servers that might end up handling this mail message. If you send mail this way, your mail is generally unlikely to be delivered.

That being the case, you'll need your PHP code to send its outgoing email through some server that is NOT on an email black list. There are a variety of mail-sending services like SendGrid, MailChimp, Amazon SES, etc. that offer SMTP access. Ie, you connect to their servers using the SMTP protocol and send your mail that way. The PHPMailer readme is probably a good place to start and has an example script that connects to an SMTP server to send outgoing mail. The trick is to get the right username, password, port, and SMTP settings -- and this tends to vary depending on who you use to deliver your mail.

If your mail volume is small enough, you can probably get away with just using a regular old gmail account.

It is important to realize, too, that just sending off an email using PHPMailer is not itself sufficient to make sure the mail gets delivered. Modern spam filters running on mail systems make use of a raft of modern, interlocking schemes to check if a mail message is legitimate or not.

In addition to the PHPMailer steps, you might also need to set up an SPF record on your domain, and possibly DKIM and DMARC credentials as well -- these are modern schemes to telegraph to other machines that your server is a legitimate source of email.

SPF is pretty simple and involves creating DNS records for your domain that identify your server as a valid source of mail.

DKIM and DMARC are a bit more involved but can dramatically improve your mail delivery rate.

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