fean
fean

Reputation: 546

php mail() from godaddy server

I'm using godaddy for hosting my site and using default godaddy mail service. Now i want to sent email using php mail function to other email address from my 1 of my 15 email address of my godaddy's email accounts

How can i fix that from which email address email will be sent and how to place the username and password for the email address ?

Thanks

Upvotes: 5

Views: 32337

Answers (6)

Perk8
Perk8

Reputation: 63

Firstly, is the website hosted with GoDaddy or do you just have email hosting with them? Our website is hosted with GoDaddy and we have our email with them as well.

Assuming you have both, then this will need to be your configuration:

//Server settings
$mail->SMTPDebug = 0;                      
$mail->isSMTP();                           
$mail->Host = localhost;                
$mail->SMTPAuth   = false;                 
$mail->Username   = SMTP_EMAIL;            
$mail->Password   = SMTP_PASSWORD;         
$mail->SMTPSecure = 'none';
$mail->Port         = 25;


//Recipients
$mail->From = "[email protected]";
$mail->FromName = "MyGoDaddyHostedDomain";
$mail->addAddress(RECIPIENT_EMAIL, RECIPIENT_NAME);     

GoDaddy assured me that security precautions are unnecessary such as SMTPAuth and SMTPSecure when your site is hosted with them and you are using their email services to send mail from a contact form.

Upvotes: 0

Kaushik C
Kaushik C

Reputation: 114

This one worked for me.

I asked Godaddy and support they told me to use relays. So Instead of using mail() function, I used PHPMailer. Kindly check below the configuration for PHP Mailer.

$mail = new PHPMailer;
$mail->isSMTP(); 
$mail->SMTPDebug = 2; 
$mail->Host = "relay-hosting.secureserver.net";
$mail->Port = 25;
$mail->setFrom('[email protected]', 'From Mail');
$mail->addAddress('[email protected]', 'To Mail');
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->msgHTML("test body 123"); 
$mail->AltBody = 'HTML messaging not supported'; 

if(!$mail->send()){
    echo "Mailer Error: " . $mail->ErrorInfo;
}else{
    echo "Message sent!";
}

Note: Here [email protected] is my mail ID which is in cPanel mail accounts.

Upvotes: 0

Erica Web Girl
Erica Web Girl

Reputation: 11

I've had this issue on a couple of client accounts. After MUCH playing around, I found that it didn't matter what email app or code you use. I finally compared two accounts. One where I know email sends from PHP, and one where it doesn't. The difference I found was:

Working account had these 2 dns entries on the domain:

  • CNAME / mail / @
  • MX / @ / mail.yourdomainname.com

And the MX Entry set within CPanel Zone Editor of:

  • Destination: yourdomainname.com

The account that was NOT working was the same, except it did not have the CNAME entry mentioned above. I added it, waited a few minutes and tested my code again and I finally started receiving the emails from my code!

Upvotes: 0

Avinash Raut
Avinash Raut

Reputation: 2113

I am using godaddy hosting . Just keep some fields blank and send mail it will work . please see below code its working for me.

<?php
include("class.phpmailer.php");
function sendMail($address,$username,$body){
            $mail = new PHPMailer();
            $mail->IsSMTP(); // telling the class to use SMTP
            //$mail->Host       = "smtp.gmail.com"; // SMTP server
            $mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
                                // 1 = errors and messages
                                                                           // 2 = messages only
            // $mail->SMTPAuth   = true;                  // enable SMTP authentication
            // $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
            // $mail->Host       = "smtp.gmail.com";      // sets  as the SMTP server
            // $mail->Port       = 465;                   // set the SMTP port for the server
            // $mail->Username   = "[email protected]";  // username
            // $mail->Password   = "test121232";            // password

            $mail->SetFrom('[email protected]', 'Contact');

            $mail->Subject    = "Enquiry for tour and travels package";



            $mail->MsgHTML($body);

            $address = $address;
            $mail->AddAddress($address, $username);
            $mail->AddCC('[email protected]');

            if(!$mail->Send()) {
            echo "Mailer Error: " . $mail->ErrorInfo;
            } else {
            echo "Message sent!";
            }
}

?>

just changed from email address, so you can send mail through this email id.

$mail->SetFrom('[email protected]', 'Contact');

Upvotes: 1

Brent Baisley
Brent Baisley

Reputation: 12721

Instead of using the mail() function, which just calls the OS mail function (i.e. sendmail), try something like SwiftMail (free PHP mail library). It support many different ways of sending mail, including logging into a mail account and sending email, just like you would do from your own computer. You could even send email from a gmail account if you wanted.

http://swiftmailer.org/

Upvotes: 3

Halcyon
Halcyon

Reputation: 57721

The PHP mail function uses the mailserver configured for that webhost. You can't change that. Since godaddy controls the mailserver they control what headers it sends. You could try inserting a custom From header but I doubt that will work. It will either get modified, flagged as spam, or rejected.

If you have 15 accounts at godaddy, perhaps it's time to look for a more serious hosting solution?

Upvotes: 8

Related Questions