Welcome! Log In Create A New Profile

Advanced

how to send mail via gmail smtp

Posted by matrixebiz 
how to send mail via gmail smtp
September 24, 2018 02:02PM
Hello, I am using a php script to send mail via a Contact Form on my webpage but I get an error saying that I have to configure the smtp stuff in php.ini. I found the php.ini-production file and the smtp sectiion but it only has a spot for smtp server, port and sendmail from. Do I not have to put a spot from my password? or since I have my gmail account set to allow sending of emails, it will just go through without needing the password?



Edited 1 time(s). Last edit at 09/24/2018 02:03PM by matrixebiz.
Re: how to send mail via gmail smtp
September 24, 2018 03:11PM
My php script is;
[code]
<?php

$EmailFrom = "test@gmail.com";
$EmailTo = "name@mail.com";
$Subject = "Nice & Simple Contact Form by CSS-Tricks";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));

// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?> [/code]


Can I just add this to the above script instead;
ini_set('SMTP','smtp.gmail.com');
ini_set('smtp_port',25);


instead of editing the php.ini? where do I put my gmail username and password?



Edited 1 time(s). Last edit at 09/24/2018 03:14PM by matrixebiz.
Re: how to send mail via gmail smtp
September 24, 2018 03:26PM
// Configuring SMTP server settings
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = $email;
$mail->Password = $password;

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: how to send mail via gmail smtp
September 24, 2018 04:24PM
Okay, thanks. Do I have to download anything else like sendmail or just put this;

// Configuring SMTP server settings
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = $email;
$mail->Password = $password;


above //validation ?



Edited 1 time(s). Last edit at 09/24/2018 04:25PM by matrixebiz.
Re: how to send mail via gmail smtp
September 26, 2018 01:25PM
Hello, doesn't seem to be working.
Getting error when I click Submit on my contact page;
This page isn’t working
www.website.com is currently unable to handle this request.
HTTP ERROR 500
Re: how to send mail via gmail smtp
September 26, 2018 01:38PM
I'm doing this on my Debian server now and I installed Sendmail so now it says Message is sent but I didn't configure it ?? When do I configure Sendmail? Thanks
Re: how to send mail via gmail smtp
September 26, 2018 01:52PM
Nevermind, it is working. I didn't have to configure anything. What server does Sendmail use by default? Does it just use my own server?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 129
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready