问题
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@domain.com','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 'address@gmail.com' or 'add@hotmail.com', it sends email to that address.But if I enter my@mydomain.com, 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('mybackupmail@gmail.com','email'), and I forwarded the incoming mail to mybackupmail@gmail.com to 'mydomain@domain.com'. It is also not sending. I almost tried everything. My mx records like below:
Should I change these settings or not? Or the problem with sth else?
I would very appreciate any help.
Thanks for interest,
回答1:
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 :)
回答2:
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@gmail.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->isHTML($html);
$mail->charSet = 'UTF-8';
$from = 'domain@gmail.com';
$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
来源:https://stackoverflow.com/questions/42248291/phpmailer-not-sending-email-on-same-domain