-1

My php code is this :

$email_message .= "Full Name: ".clean_string($full_name)."\r\n";
$email_message .= "Email: ".clean_string($email_from)."\r\n";
$email_message .= "Telephone: ".clean_string($telephone)."\r\n";
$email_message .= "Message: ".clean_string($comments)."\r\n";

$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
header("Location: $thankyou");
?>
<script>location.replace('<?php echo $thankyou;?>')</script>
<?php
}
die();
?>

It is like a feedback form. I get the name, email, telephone and message from the visitor. Then I used php mail() function to send these details to my email.(the $email_to variable is in another file which I integrated with this file). When I try to fill out the form and send it, the mail is not reaching my id. Then i heard of SMTP used to send emails.

but I couldn't make out how to integrate SMTP (my id is in GMail. so smtp.gmail.com) in this coding. Help appreciated

Michel
  • 490
  • 4
  • 11
Siddharth Venu
  • 1,318
  • 13
  • 26
  • By default Gmail won't let you send emails to yourself – [specifically](https://support.google.com/a/answer/1703601?hl=en): "To prevent clutter, Gmail doesn't route messages that you send to your own alias to your inbox." – William Turrell Sep 21 '15 at 13:23

1 Answers1

0

Just guessing but you inverted letters in SMTP.. (smtp.gmail.com

Take a look at this one: Send email using the GMail SMTP server from a PHP page

copied from the answer:

// Pear Mail Library
require_once "Mail.php";

$from = '<from.gmail.com>';
$to = '<to.yahoo.com>';
$subject = 'Hi!';
$body = "Hi,\n\nHow are you?";

$headers = array(
    'From' => $from,
    'To' => $to,
    'Subject' => $subject
);

$smtp = Mail::factory('smtp', array(
        'host' => 'ssl://smtp.gmail.com',
        'port' => '465',
        'auth' => true,
        'username' => 'johndoe@gmail.com',
        'password' => 'passwordxxx'
    ));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
    echo('<p>' . $mail->getMessage() . '</p>');
} else {
    echo('<p>Message successfully sent!</p>');
}
Community
  • 1
  • 1
Lance
  • 21
  • 3