php - smtp server - php

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.

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

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

Joomla Send Mail with JUtility::sendMail sender email issue

I faced an issue in Joomla JUtility::sendMail function
The function arguments mentioned in the Joomla documentation is like this
The issue is i can't set the fromemail(Sender email).When i set the sender email and replay to email .The replay to email is showing in the mail is the one from joomla admin config email.
when i set the other email in replay to or sender email Its not taking correct one every time its using the email from joomla admin config.
I got one refference from google almost same but I tried this it not working.
I am using Joomla 1.7
I tried with
$your_email //can be array but here string one email
$your_name //name i will work fine
$user_email //admin email
$subject //subject
//last two argument is reply to and replay name Its showing inside mail but click on replay it will admin config email.
JUtility::sendMail($your_email, $your_name, $user_email, $subject, $fcontent,1,NULL,NULL,NULL,$your_email,$your_name);
Any help will appreciated..
Try like this
$mailer =& JFactory::getMailer();
//add the sender Information.
$sender = array(
$your_email,
$your_name
);
$mailer->setSender($sender);
//add the recipient.
$recipient = $user_email;
$mailer->addRecipient($recipient);
//add the subject
$mailer->setSubject('Your subject string');
//add body
$mailer->setBody($fcontent);
$send =& $mailer->Send();
if ( $send !== true ) {
echo 'Error sending email: ' . $send->message;
} else {
echo 'Mail sent';
}
It's done.For more information see this link Sending email from extensions.
I thinks it may help you.

php - not able te receive the email

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

Categories