cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Go to solution

Using phpmailer to send a contact us form from cPanel email account

I'm using phpmailer to send a simple form submission from a cPanel email account to itself. If I understand correctly, I am supposed to use localhost and port 25, but I can't get it to work, with no errors.

 

I have the email configured for local mx routing, and the DNS MX entry points to mail.<my-domain>.com.

 

Here's the php:

<?php

//Import the PHPMailer class into the global namespace
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';

if (array_key_exists('submit', $_POST)) { $err = false; $msg = ''; $email = ''; if (array_key_exists('message', $_POST)) { $message = substr(strip_tags($_POST['message']), 0, 16384); } else { $message = ''; $msg = 'No message provided!'; $err = true; } if (array_key_exists('name', $_POST)) { $name = substr(strip_tags($_POST['name']), 0, 255); } else { $name = ''; } $to = 'cpanelaccount'; if (array_key_exists('email', $_POST) and PHPMailer::validateAddress($_POST['email'])) { $email = $_POST['email']; } else { $msg = "Error: invalid email address provided"; $err = true; } if (!$err) { $mail = new PHPMailer; $mail->isSMTP(); $mail->Host = 'localhost'; $mail->Username = "cpanelaccount"; $mail->Password = "cpanelaccountpass"; $mail->Port = 25; $mail->CharSet = 'utf-8'; $mail->setFrom('cpanelaccount', (empty($name) ? 'Contact form' : $name)); $mail->addAddress($to); $mail->addReplyTo($email, $name); $mail->Subject = 'New message from website visitor!'; $mail->Body = "Contact form submission\n\n" . $message; if (!$mail->send()) { $msg .= "Mailer Error: " . $mail->ErrorInfo; } else { $msg .= "Message sent!"; } } } ?>

 

3 REPLIES 3
Highlighted
Community Manager
Community Manager
Solution

Re: Using phpmailer to send a contact us form from cPanel email account

Hi @johnEOlson. Welcome to GoDaddy Community! Try using relay-hosting.secureserver.net instead of localhost. All mail that goes out from our hosting plans needs to route through that server. You can still use port 25. No authentication is needed. Hope that helps. 

 

JesseW - GoDaddy | Community Manager | 24/7 support available at x.co/247support | Remember to choose a solution and give kudos.

Re: Using phpmailer to send a contact us form from cPanel email account

Thanks for the reply Jesse! I'm still not getting the mail to get through. It's been 48 hours since I changed the MX entry to point to mail.<mydomain>.com, and I'm using relay-hosting.secureserver.net, port 25. I'm going to start going through the phpmailer debugging tools to see if mail is at least getting generated at all. Thanks for your help my friend.

Re: Using phpmailer to send a contact us form from cPanel email account

Got it working now, that host worked! Thanks Jesse!