user3346438
user3346438

Reputation: 1

my contact form php won't send an email via smtp to my gmail account

I am trying to insert the php code SMTP via gmail so it can send through smtp.gmail.com, and it doesn't seem to work. I someone can give me a hand so I can get it working, it would be a great help.

p.s. with out this scrpit it works on a server that already has the smtp setup. I am trying to insert it so I can use it on another server with out mail server.

  `($host = "ssl://smtp.gmail.com";
$port = "465";
$username = "<[email protected]>";
$password = "********";)`

`

    $host = "ssl://smtp.gmail.com";
$port = "465";
$username = "<[email protected]>";
$password = "********";

$mail_to = '[email protected]'; 

$name = $_POST['sender-name'];
$mail_from = $_POST['sender-email'];
$phone = $_POST['sender-phone'];
$message = $_POST['sender-message'];

$subject = 'localhost/wilkinson-sport Messaggio da un visitatore ' . $name;

$body_message .= 'Da: ' . $name . "\r\n";
$body_message .= 'E-mail: ' . $mail_from . "\r\n";
$body_message .= 'Telfono: ' . $phone . "\r\n";
$body_message .= 'Commenti: ' . $message;


$headers .= 'Da: ' . $mail_from . "\r\n";
$headers .= 'Rispondi a: ' . $mail_from . "\r\n";

$mail_sent = mail($mail_to, $subject, $body_message, $headers); 

if ($mail_sent == true){ 

if (isset($_POST) && $_POST['accetto'] == "si")
{               
    echo ("<script>alert('Hai accettato il consenso privacy.')</script>");
}
else if (isset($_POST) && $_POST['accetto'] == "no")
{
    echo ("<script>alert('Non hai accettato il consenso privacy. Riprova!')</script>");
}
else if (isset($_POST) && $_POST['entra'] == false)
{
    echo ("<script>alert('Devi accettare il consenso privacy per accedere!')</script>");
} 
} 


?>`

Upvotes: 0

Views: 433

Answers (1)

dimartiro
dimartiro

Reputation: 111

Try using PHPMailer, a class for mail transfers https://github.com/PHPMailer/PHPMailer

Upvotes: 1

Related Questions