Harun Yılmaz
Harun Yılmaz

Reputation: 98

Phpmailer not sending email on same domain

I have a website and there is a contact form. My code below :

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

$mail = new PHPMailer(true);

if (!$mail->addAddress('[email protected]','email')) {
  die('Invalid email address');
}
$mail->isSMTP();
//$mail->SMTPAuth = true;
$mail->SMTPDebug = 2;
$mail->Host = 'localhost';
$mail->Subject = 'Subject';
$text = 'A mail...';
$mail->MsgHTML($text);
$mail->SetFrom($email);
//$mail->AddReplyTo($email,$name);

if ($mail->Send()){

If user enter his/her mail adress like '[email protected]' or '[email protected]', it sends email to that address.But if I enter [email protected], it says message send, but mail is not arrived. I'm searching for 2 days but can not found proper solution. I did also try this:

I wroted $mail->addAddress('[email protected]','email'), and I forwarded the incoming mail to [email protected] to '[email protected]'. It is also not sending. I almost tried everything. My mx records like below:

enter image description here

Should I change these settings or not? Or the problem with sth else?

I would very appreciate any help.

Thanks for interest,

Upvotes: 2

Views: 3786

Answers (2)

EdB
EdB

Reputation: 51

Are you using a cpanel hosting with godaddy? I dunno if this is "cpanel everywhere", or just at godaddy, but go into your cpanel and look for a thing called "MX Entry" then change it from local to remote. Local tells the server "we are the mail engine for this domain that we have here in this cpanel", and remote tells it "the email for this domain is handled outside of cpanel" ... your MX records tell me you're using workspace email, thus you need MX Entry to remote :)

Upvotes: 5

Mohammad
Mohammad

Reputation: 497

Function sample send email with phpmailer

you just change path include

and change parameters

function send_email($to, $subject, $message, $html = TRUE)
{
    require_once APPPATH .'libraries/phpmailer/PHPMailerAutoload.php';

    $mail                   = new PHPMailer;

    $mail->isSMTP();

    $mail->SMTPDebug        = 0;
    $mail->Debugoutput      = 'html';

    $mail->Host             = 'smtp.gmail.com';
    $mail->SMTPAuth         = true;
    $mail->Username         = '[email protected]';
    $mail->Password         = 'password';
    $mail->SMTPSecure       = 'tls';
    $mail->Port             = 587;

    $mail->isHTML($html);
    $mail->charSet          = 'UTF-8';


    $from = '[email protected]';

    $mail->setFrom($from, 'no-reply');
    $mail->addAddress($to, 'Information');

    $mail->Subject          = '=?UTF-8?B?'.base64_encode($subject).'?=';
    $mail->Body             = $message;
    $mail->AltBody          = '';

    if($mail->send())
    {
        return TRUE;
    }

    return FALSE;
}

OR sample : This example shows sending a message using PHP's mail() function

Upvotes: 0

Related Questions