Harun Yılmaz
Harun Yılmaz

Reputation: 98

Godaddy phpmailer smpt configuration

We have a site on godaddy server. We have a contact form. When user filled form, first we should send mail to our info@oursite, after we should send mail to user's mail from our info@oursite. My tried code below:

$name = $_POST['name'];
$email = $_POST['email'];


$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug  = 2;
$mail->port = 25;
$mail->Host = 'localhost';
$mail->Username = '[email protected]';
$mail->Password = 'password';
$mail->addAddress($email, $name);
$mail->subject = 'Subject';
$mail->MsgHTML('mail içeriği');


if ($mail->Send()){

this outputs below:

enter image description here

it seems mail delivered, but it never delivered the message. I tried many things;

$mail->SMTPAuth = true;

port 25,80,3535,465(with ssl), tls, ssl authentication,

what should I do? what should I try more, any ideas?

Upvotes: 0

Views: 411

Answers (1)

Synchro
Synchro

Reputation: 37710

First of all, you're using a very old version of PHPMailer; get the latest.

I don't know where you got your code, but you've got the case of some vital properties wrong - I suggest you base your code on the examples provided with PHPMailer. In particular, subject should be Subject and port should be Port. When sending to localhost you don't need a username or password, so you don't need to set them. Similarly, Port defaults to 25, so you don't need to set it.

You're not specifying a From address, and it looks like whatever address you're passing to addAddress is invalid, so you're sending a message from nobody to nobody - and not surprisingly it's not going anywhere!

It looks like your message body is in Turkish (?), which will not work in the default ISO-8859-1 character set, so I suggest you switch to UTF-8 by setting $mail->CharSet = 'UTF-8';.

Check your return values when calling addAddress to make sure the submitted value is valid before trying to send to it.

With these things fixed:

$name = $_POST['name'];
$email = $_POST['email'];

$mail = new PHPMailer;
if (!$mail->addAddress($email, $name)) {
  die('Invalid email address');
}
$mail->isSMTP();
$mail->CharSet = 'UTF-8';
$mail->SMTPDebug = 2;
$mail->Host = 'localhost';
$mail->Subject = 'Subject';
$mail->msgHTML('mail içeriği');
$mail->setFrom('[email protected]', 'My Name');    

if ($mail->send()) {
    echo 'Sent';
} else {
    echo 'Error: '.$mail->Errorinfo;
}

Upvotes: 1

Related Questions