php - not able te receive the email - php

Below is the code
<?php
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
include('config.php');
// table name
$tbl_name="temp_members_db";
// Random confirmation code
$confirm_code=md5(uniqid(rand()));
// values sent from form
$name=$_POST['name'];
$email=$_POST['email'];
$country=$_POST['country'];
// Insert data into database
$sql="INSERT INTO $tbl_name(confirm_code, name, email, password, country)VALUES('$confirm_code', '$name', '$email', '$password', '$country')";
$result=mysql_query($sql);
// if suceesfully inserted data into database, send confirmation link to email
if($result){
// ---------------- SEND MAIL FORM ----------------
// send e-mail to ...
$to=$email;
// Your subject
$subject="Your confirmation link here";
// From
$header="from: your name <your email>";
// Your message
$message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
//$message.="http://www.yourweb.com/confirmation.php?passkey=$confirm_code";
$message.="http://localhost/confirmation.php?passkey=$confirm_code";
// send email
$sentmail = mail($to,$subject,$message,$header);
}
// if not found
else {
echo "Not found your email in our database";
}
// if your email succesfully sent
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send Confirmation link to your e-mail address";
}
?>

Some mailservers ( IE MailEnable ) aint handling the FROM correctly
a fix would be this
$header="FROM: your name <your email>";
To
$header="FROM: your email";

whats the error you are getting and i think you try to send a email , if a mail server is not configured in local host you cant send emails
you can use a SMTP class to send mails using your SMTP mails like gmail

Related

Only receive emails from gmail when users submit my forms and not yahoo or icloud using phpmailer [duplicate]

This question already has answers here:
How do you make sure email you send programmatically is not automatically marked as spam?
(24 answers)
Closed 4 years ago.
I have a simple website set up on godaddy, decided to add emails straight to me instead of through godaddy, started using the phpmailer and I only receive emails from users submitting on my website form if they send an email with gmail. All other emails get ignored. Wonder if it's a godaddy issue.
$connect = mysqli_connect('localhost', 'pf', '*********', 'bs-portf');
if(mysqli_connect_errno()){
echo "Failed to connect" . mysqli_connect_error();
}
if(mysqli_ping($connect)){
// echo "we are connected";
}else{
echo "Error: ". mysqli_error($connect);
die("Connection failed");
}
?>
<?php
if(isset($_POST['submit'])){
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPmailer();
$name = $_POST['name'];
$email = $_POST['email'];
$message = nl2br($_POST['message']); //nl2br() new lines in text message to break tags
$mail->Host='smtp.gmail.com';
// $mail->isSMTP();
$mail->Port=465;
$mail->SMTPAuth=true;
$mail->SMTPsecure='ssl';
$mail->Username='bradv#gmail.com';
$mail->Password='**********';
$mail->setFrom($email, $name);
$mail->addAddress('bradv#gmail.com');
$mail->addReplyTo('info#example.com', 'Information');
$mail->isHTML(true);
$mail->Subject='Form Submission';
$mail->Body= "test email body 1";
// $mail->Body='<p align=center>Name :'.$name. '<br>Email: '.$email.
'<br>Message '.$message. '</p>';
// echo "submit worked";
if($mail->send()){
echo 'mail is sent';
// $result ="Something went wrong. Please try again.";
}else{
echo 'email failed';
// $result="Thanks " .$name. " for contacting us. We'll get back to you
soon!";
}
Check the spam folder. If you send an email using one address as login but sets the From address as another, Gmail will think its spam.
Set from address with the same email as the login and replyto as the user's email.

Need help sending email in PHP using Gmail SMTP

So I'm trying to follow the instructions here
http://www.9lessons.info/2011/07/send-mail-using-smtp-and-php.html
to use PHP to send out an email using my gmail account. But when I try to send a test email I get in the web browser this message: Error: could not connect to the host "smtp.gmail.com"
Here is are my two files (with my personal data edited)
Thanks for any help
<?php
print "1";
require("smtp.php");
require("sasl.php"); //SASL authentication
$from="support#yourwebsite.com";
$smtp=new smtp_class;
$smtp->host_name="smtp.gmail.com"; // Or IP address
$smtp->host_port=465;
$smtp->ssl=0;
$smtp->start_tls=1;
$smtp->localhost="localhost";
$smtp->direct_delivery=0;
$smtp->timeout=10;
$smtp->data_timeout=0;
$smtp->debug=1;
$smtp->html_debug=1;
$smtp->pop3_auth_host="";
$smtp->user="john#gmail.com"; // SMTP Username
$smtp->realm="";
$smtp->password="House22"; // SMTP Password
$smtp->workstation="";
$smtp->authentication_mechanism="";
print "3";
if($smtp->SendMessage(
$from,
array(
$to
),
array(
"From: $from",
"To: $to",
"Subject: $subject",
"Date: ".strftime("%a, %d %b %Y %H:%M:%S %Z")
),
"$message"))
{
print "Message sent to $to OK.";
}
else
print "Cound not seend the message to $to.\nError: ".$smtp->error;
print "4";
?>
==============================
<?php
$to="ralph#website.com";
$fn="First Name";
$ln="Last Name";
$name=$fn.' '.$ln;
$from="test#grove.net";
$subject = "Welcome to Website";
$message = "Dear $name,
Your Welcome Message.
Thanks
www.website.com
";
include('smtpwork.php');
?>
as per Gmail policy, You cannot use plain password (house22), you have to use encrypted password(Gh45515HGGujKkkHk5554), for that you need two way authentication should be enable on your gmail account. and after that, create Application Specific Password and then use that password for your SMTP, I hope that will work for you. here is the link1 Link2

Trying to create a php auto email after a form has been submitted, and style the email with HTML

I'm building a form that allows someone to sign up for a deal. I want the form to send 3 emails using php once it has been submitted; one sending the details of the form to myself, one sending the details to the person offering the deal, and one sending the actual deal confirmation and voucher to the person who signed up.
I've run into problems in that certain email addresses don't seem to receive or be sent the email when i'm testing it (it works for both my hotmail and gmail addresses, but not for my own domain email address). I also can't figure out how to add some sort of html style to the emails being sent.
How can I style these emails and make sure that they are being sent to right email addresses?
here is the code:
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['name'];
$airline=$_REQUEST['airline'];
$position=$_REQUEST['position'];
$checkin=$_REQUEST['checkin'];
$attendance=$_REQUEST['attendance'];
$email=$_REQUEST['email'];
$terms=$_REQUEST['terms'];
if (($name=="")||($position=="")||($checkin=="")||($attendance=="")||($email==""))
{
echo "All fields are required, please fill the form again.";
}
//email going to me//
else{
$from="From: Deal 1 Form Submission<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("myemail#test.com",
$subject,
$message="someones taken the deal: heres their info: <br> Name: $name\nAirline: $airline\nPosition: $position\nCheckin: $checkin\nAttendance: $attendance\nEmail: $email\n" );
echo "Email sent!";
}
//email going to the customer//
{
$from="From: me<myemail#test.com>\r\nReturn-path: $email";
$subject="Thank you for choosing this deal";
mail("$email", $subject, $message="thanks for choosing this deal!, please present this voucher when attending the restaurant", $from );
}
//email going to the partner//
{
$from="From: Me<myemail#test.com>\r\nReturn-path: $email";
$subject=" Great news! Someone has chosen your deal";
mail("partneremail#test.com",
$subject,
$message="Fantastic news, a customer has taken your deal! here's their info: Name: $name\nAirline: $airline\nPosition: $position\nCheckin: $checkin\nAttendance: $attendance\nEmail: $email\n
", $from );
}
}
?>
Many thanks.
Your best bet is to use PHPMailer. Here is some example code that relays the email through gmail. The reason why you would want to do this is to avoid emails from the server going into you spam box.
$debug = true; // set it to false in production
$Mail = new PHPMailer();
if ($debug) {
// this allows you to see the details of the connection to gmail
$Mail->SMTPDebug = 4;
}
$Mail->isSMTP();
$Mail->Host = 'smtp.gmail.com';
$Mail->SMTPAuth = true;
$Mail->Username = 'your#gmail.com';
$Mail->Password = '[your-password]';
$Mail->SMTPSecure = 'tls';
$Mail->Port = 587;
$Mail->setFrom('from#address.com', 'John Smith');
$Mail->addAddress('to#address.com', 'Someone Else');
$Mail->addReplyTo('from#address.com', 'John Smith');
$Mail->addBCC('bcc#address.com', 'BCC Person');
$Mail->addAttachment('path/to/img/or/pdf/or/whatever/you/want/to/attach.pdf');
$Mail->Subject = 'Test Subject';
$Mail->Body = '<h1>Hi! This is an HTML format body'
$Mail->AltBody = 'Hi! Im just a text email in case HTML is not supported!';
if (!$Mail->send()) {
print $Mail->ErrorInfo;
return false;
} else {
return true;
}

Issue with PHP mail form

Basically I have my PHP send an email to the person who signed up so then they their email will be verified. I did a test run and the link is generated with my database, its just the email that isn't making its way to the inbox. I'm not sure if its a delay or its an issue with the code, but any help would be much appreciated.
PHP For Email To Be Sent:
<?php
include('config.php');
// table name
$tbl_name=temp_members_db;
// Random confirmation code
$confirm_code=sha1(uniqid(rand()));
// values sent from form
$name=$_POST['name'];
$email=$_POST['email'];
// Insert data into database
$sql="INSERT INTO $tbl_name(confirm_code, name, email, password)VALUES('$confirm_code', '$name', '$email', '$password')";
$result=mysql_query($sql);
// if suceesfully inserted data into database, send confirmation link to email
if($result){
// ---------------- SEND MAIL FORM ----------------
// send e-mail to ...
$to=$email;
// Your subject
$subject="Your confirmation link here";
// From
$header="from: Colourity <your email>";
// Your message
$message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="http://www.colourity.com/confirmation.php?passkey=$confirm_code";
// send email
$sentmail = mail($to,$subject,$message,$header);
}
// if not found
else {
echo "Not found your email in our database";
}
// if your email succesfully sent
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send Confirmation link to your e-mail address";
}
?>
You can use a PHP class like HTML Mime Mail (RMail) to act like a SMTP client to send your email. You will need a valid email account to use and your web server will still need to be able to send data out to whatever port you email account requires (usually port 25, 465, or 587).
I would recommend SwiftMailer. Instructions on using SMTP—to connect to another account to mail it—is located here.
require_once 'lib/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25)
->setUsername('your username')
->setPassword('your password')
;
/*
You could alternatively use a different transport such as Sendmail or Mail:
// Sendmail
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
// Mail
$transport = Swift_MailTransport::newInstance();
*/
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('john#doe.com' => 'John Doe'))
->setTo(array('receiver#domain.org', 'other#domain.org' => 'A name'))
->setBody('Here is the message itself')
;
// Send the message
$result = $mailer->send($message);
But all that said, I would investigate if your host can handle localhost mailing since that is the easiest to use if you have that available.
I would recommend PHPmailer Library. Very easy to use for sure.
https://github.com/Synchro/PHPMailer

php - smtp server

I am working on a project. For that i have downloaded smtp server on ubuntu. Could any one please tell me the command to check whether the smtp server install properly or not. because email is not getting generated.
Below is the code for your reference
<?php
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
include('config.php');
// table name
$tbl_name="temp_members_db";
// Random confirmation code
$confirm_code=md5(uniqid(rand()));
// values sent from form
$name=$_POST['name'];
$email=$_POST['email'];
$country=$_POST['country'];
// Insert data into database
$sql="INSERT INTO $tbl_name(confirm_code, name, email, password, country)VALUES('$confirm_code', '$name', '$email', '$password', '$country')";
$result=mysql_query($sql);
// if suceesfully inserted data into database, send confirmation link to email
if($result){
// ---------------- SEND MAIL FORM ----------------
// send e-mail to ...
$to=$email;
// Your subject
$subject="Your confirmation link here";
// From
$header="FROM: your email";
// Your message
$message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
//$message.="http://www.yourweb.com/confirmation.php?passkey=$confirm_code";
$message.="http://localhost/confirmation.php?passkey=$confirm_code";
// send email
$sentmail = mail($to,$subject,$message,$header);
}
// if not found
else {
echo "Not found your email in our database";
}
// if your email succesfully sent
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send Confirmation link to your e-mail address";
}
?>
First check. Is it listening on the standard SMTP port 25 ? (e.g. telnet localhost 25 - does this connect?)
Second check. What do the log files say ? The doc should indicate where those logs are (/var/log perhaps?)
Check if sudo /etc/init.d/postfix restart gives errors, change postfix to mail server that you installed.

Categories