PHP Mailer Help

Here’s the situation: I have a contact form that uses a PHP Mailer to send messages to a [email protected] address. This [email protected] address forwards all messages to my business address.

I have 4 fields users enter information in: Name, Email, Subject, Message

Here’s the issue: users who enter Gmail addresses into the Email part of the form can not send a message to me. All other email address domains work perfectly. Just not Gmail. I am not sure how to fix it. Any help would be greatly appreciated ;D Here is my code:

[php]

<?php require 'PHPMailer/PHPMailerAutoload.php'; $host = 'host'; $username = 'address'; $password = 'password'; $send = false; // Subject $subject = addslashes(strip_tags($_POST['subject'])); // Name $name = addslashes(strip_tags($_POST['name'])); // Email $email = addslashes(strip_tags($_POST['email'])); // Message $message = addslashes(strip_tags($_POST['message'])); // Services $services = ''; if ( isset($_POST['services']) AND count($_POST['services']) > 0) { $index = 1; foreach ( $_POST['services'] as $val) { $services .= ( $index == count($_POST['services'])) ? $val : $val . ', '; $index++; } } else { $services .= '-'; } // Project Class if ( isset($_POST['project_class']) AND $_POST['project_class'] <> '') { $project_class = addslashes(strip_tags($_POST['project_class'])); } else { $project_class = '-'; } $htmlmessage = <<<MESSAGE $subject

Name: $name

Email: $email

Message: $message

Services: $services

Project Class: $project_class

MESSAGE; $mail = new PHPMailer(); $mail->isSMTP(); $mail->Host = $host; $mail->Username = $username; $mail->Password = $password; $mail->SMTPAuth = true; // authentication enabled $mail->SMTPSecure = 'ssl'; // sets the prefix to the servier (ssl / tls) $mail->Port = 465; // set the SMTP port for the dreamhost email server $mail->IsHTML(TRUE); $mail->From = $email; $mail->FromName = $name; // Add receive email address $mail->addAddress($username); $mail->isHTML(true); $mail->Subject = $subject; $mail->Body = $htmlmessage; // Send the message, check for errors if ( $mail->send()) { $send = true; } echo json_encode($send); [/php]

UPDATE:

Also, yahoo addresses do not work. So its gmail and yahoo.

It sounds like a spam issue honestly. Why are you using addslashes()? It is not going to a database, not that you should be using that function anyways. It also appears you are missing these portions of the code:

[php]
$mail->SetFrom(‘[email protected]’, ‘First Last’);
$mail->AddReplyTo("[email protected]",“First Last”);[/php]

Without them, some spam filters auto block them before they allow them to the server.

I’ve added the SetFrom and the AddReplyToo lines, but gmail or yahoo still doesnt work in the email field of the contact form.

I’m going to guess it has something to do with the following:
[php]$mail->Port = 465; // set the SMTP port for the dreamhost email server[/php]

I don’t think gmail or yahoo uses that port? (I could be wrong, for this is only guess).

What I do is use $mail->isSendMail() instead of $mail->isSmtp(), I find it more reliable (in most cases).
[php] if (filter_input(INPUT_SERVER, ‘SERVER_NAME’, FILTER_SANITIZE_URL) == “localhost”) {
$this->mail->isSmtp(); // Local Host:
$this->mail->Port = EMAIL_PORT; // Local Host Port: (Usually 587)
} else {
$this->mail->isSendMail(); // Remote Host:
}[/php]

I want to say he’s using a dreamhost mail server, but I don’t see it anymore.
At his is coming to you, correct? Have you checked you spam folders?

Sponsor our Newsletter | Privacy Policy | Terms of Service