Here is code for sending email from localhost after i referred a lot from online.
html form:
<form method="post" action="email.php">
Email: <input name="email" id="email" type="text" /><br />
Message:<br />
<textarea name="message" id="message" rows="15" cols="40"></textarea><br />
<input type="submit" value="Submit" />
</form>
email.php:
<?php
// $email and $message are the data that is being
// posted to this page from our html contact form
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
require_once('class.phpmailer.php');
require 'PHPMailerAutoload.php';
require 'class.smtp.php';
$mail = new PHPMailer();
$body='hellooooo';
$mail->IsSMTP();
$mail->Host = "ssl://smtp.gmail.com"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "mygmailid#gmail.com"; // SMTP username
$mail->Password = "mypassword"; // SMTP password
$mailer->SMTPSecure = 'ssl';
$mailer->Port = 465;//587;
$mail->AddAddress("bradm#inmotiontesting.com", "Brad Markle");
$mail->SetFrom('xxxxxxxx#gmail.com','Selva Rani');
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "You have received feedback from your website!";
$mail->MsgHTML($body);
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
so when i run my code, i received mail but time is correct in gmail,
If i use hotmail means, the received time is not correct.
May i know know?
Anyone can help me?
Thanks,
Note: I m new to php, but i want to know particular this one and fix the problem. and I referred similar questions in stack, but it didn't help me,
Can anybody help me to fix this?
Thanks,
when i check my email acc, it shows like this,
so in that image, the time showed., 8.48AM, it is not correct according to indian time, it need to show 2.05PM ..
According to my question,
For hotmail time settings,
I modified my hotmail acc, after that it will work,
The steps are,
Log into your Hotmail Account
Click on Options in the upper right corner of the page
Under "Manage Your Account, click on the option "View and edit your personal information"
One the Account Summary page, click the link name "Registered information" under your birthdate
Select your correct country in the Home Location section
Select your correct time zone in the Time Zone section.
Click on the Save tab
Related
As a relative newbie to PHP I've been very impressed with the ease of implementation of the functionalities behind PHPMailer 5.2.0 so far for use on the contact me page of my website which is still under construction. However, I have a small problem and have been searching all of SO, the PhpMailer GitHub, and the rest of the web for a solution for the last few hours and I am completely stumped to be honest as none of the answers seem to quite fit what problem I am experiencing.
What I want on my website's contact form page is to allow users to send me an email using my form including their full name, email address, any attachments they want to send, and their message followed by my email signature.
The current situation is this; when a user fills out the contact form on the contact.html page the results are posted to the email.php form and everything is sent to my email as it is supposed to, followed by sending an auto-response message to the senders email address. However, I am not receiving the attachments in the emails, but i can receive both the initial email and the auto-response if I use another email account I can access, and they are not being uploaded to the uploads folder in my website directory.
I think, from what I have read so far, that I have incorrectly set up 2 things and am also unable to find a php.ini file in my website directory.
The first thing is the structure of my websites public_html folder which contains the following related files and folders; contact.html, email.php, class.phpmailer.php, class.smtp.php, PHPMailerAutoload.php, and a folder called uploads with the privileges set to enable read and write by all user types.
The second thing I assume is wrong is in the following extract of PHP code, taken from the included example in the PHPMailer Git download (the example is not wrong, just my use of it), which I should probably edit to point to the uploads folder instead of "sys_get_temp_dir()":
//Attach multiple files one by one
for ($ct = 0; $ct < count($_FILES['userfile']['tmp_name']); $ct++) {
//The line below may be looking for the wrong directory?
$uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['userfile']['name'][$ct]));
$filename = $_FILES['userfile']['name'][$ct];
if (move_uploaded_file($_FILES['userfile']['tmp_name'][$ct], $uploadfile)) {
$mail->addAttachment($uploadfile, $filename);
} else {
}
}
The current form is coded similarly to below, having been trimmed of all unnecessary styling for easy reading, in the file "contact.html":
<form method="post" action="email.php" enctype="multipart/form-data">
<div>
<input type="text" id="name" name="name" placeholder="Your Name" required>
</div>
<div>
<input type="email" id="email" name="email" placeholder="Your Email Address" required>
</div>
<div>
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
<input type="file" id="userfile" name="userfile[]" multiple="multiple">
</div>
<div>
<textarea rows="20" id="message" name="message" placeholder="Your message Text..." required></textarea>
</div>
<div class="recaptchaContainer">
<div class="g-recaptcha" data-sitekey="*" data-callback="enableBtn">
</div>
<div>
<button id="sendMsgBtn" type="submit">
Send Message
</button>
<p id="response"></p>
</div>
</form>
And the email.php code it posts to, as defined in the form tag:
<?php
// When we unzipped PHPMailer, it unzipped to
// public_html/PHPMailer_5.2.0
require("PHPMailerAutoload.php");
$mail = new PHPMailer;
// $name, $email, and $message are the data that is being
// posted to this page from our html contact form
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$file = 'images/test.jpg' ;
$message = $_REQUEST['message'] ;
/*Attach multiple files one by one
for ($ct = 0; $ct < count($_FILES['userfile']['tmp_name']); $ct++) {
$uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['userfile']['name'][$ct]));
$filename = $_FILES['userfile']['name'][$ct];
if (move_uploaded_file($_FILES['userfile']['tmp_name'][$ct], $uploadfile)) {
$mail->addAttachment($uploadfile, $filename);
} else {
}
}*/
$emailsig = 'Email signature...' ;
// set mailer to use SMTP
//$mail->IsSMTP();
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = "TLS";
$mail->Host = 'smtp.live.com';
$mail->Port = '587';
// Email address & Password:
$mail->Username = "************#**********.com"; // SMTP username
$mail->Password = "******************"; // SMTP password
// $email is the user's email address the specified
// on our contact us page. We set this variable at
// the top of this page with:
// $email = $_REQUEST['email'] ;
$mail->From = $email;
$mail->FromName = $name;
// below we want to set the email address we will be sending our email to.
$mail->AddAddress("****************#***************.com", "***********");
// set word wrap to 50 characters
$mail->WordWrap = 50;
$mail->Subject = "You have received feedback from " . $name . " via your website!";
$mail->AddAttachment( $file, 'test.jpg' );
// $message is the user's message they typed in
// on our contact us page. We set this variable at
// the top of this page with:
// $message = $_REQUEST['message'] ;
$mail->Body = nl2br($message) . $emailsig;
$mail->AltBody = $message;
$mail->IsHTML(true);
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
} else {
$mail->ClearAllRecipients();
$mail->ClearAttachments();
$mail->From = "*********#*********.com";
$mail->FromName = "******** - Auto-Response";
$mail->AddAddress($email, $name);
$mail->Subject = "Auto-reply message from ********!";
$message = 'Some auto-reply message text here...';
$mail->Body = nl2br($message) . $emailsig;
$mail->send();
echo "Message has been sent successfully!";
}
?>
I have a feeling it is due to a problem with what I have done (or not done) on my web server combined with not pointing to the upload folder in my directory and maybe even not pulling the files across to my php file initially? What I would like to know really is a step-by-step set of instructions for sorting out my code and setting this up on my web server if anyone can help?
I very much appreciate the fact that my question will probably have WAY too much detail and is probably an easy fix for someone who is an expert on this sort of thing, I just wanted you to have all the information at your disposal to make working this one out a bit easier.
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 8 years ago.
I have a very simple contact form and a very simple php mail script. But when I tried to send it to the specified email address, I did not receive the test mail.
Below are my codes:
HTML Form
<div class="form" >
<form action="mail.php" method="post">
Email: <input type="text" name="email" size="38"><br>
詢問主旨:<input type="text" name="subject" size="36"><br>
<div class="queryTitle">
詢問內容
</div>
<br>
<textarea name = "message" rows="6" cols="37">
</textarea>
<br>
<input name = "submitted" type="submit" value="傳送">
</form>
</div>
Php script:
<?php
if (isset($_REQUEST['submitted'])) {
if (empty($errors)) {
$from = "From: ".$_REQUEST['email']."\r\n"; //Site name
// Change this to your email address you want to form sent to
$to = "verymeanguy2#gmail.com";
$subject = $_REQUEST['subject'];
$message = $from." ".$_REQUEST['message'];
mail($to,$subject,$message,$from);
}
}
?>
Could it be that Gmail blocked my mail? If so, how can I devise a script that can send mails to the popular mails?
Thanks in advance!
Jason
PS: I am hosting mine on heliohost's free Stevie server, if that accounts for something.
lolka_bolka: yes, mail() was called and adding an echo in front of mail function prints 1. And it's not in spam. Len_D: it did print anything, so I think mail was called and returned true. Anthony: how do I ensure that?
I just want to report back my testing. It seems that Gmail blocks Yahoo mail address sender for some reason. When the header is a Gmail address or even a bogus made-up address, Gmail can receive no problem. Yahoo mail on the other hand can receive mail with no problem at all. Anyone can shed a light on that?
When mail returns true (or 1), it means it did correctly what it tried to do. But doesn't always mean it sent mail at all.
the mail() funciton uses "sendmail" to actually send the email.
If sendmail is configured to send mail, then that's what will happen (it everything went ok).
However, by defult, sendmail stores mail in the server. It "simulates" a real sendmail.
From my personal experience, I recommend PHPMailer. It's easy to use, it's much easier to check for errors (check if the email was sent, and if not, get infomation about the problem).
Example:
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.server.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Username = "email#domain.com";
$mail->Password = "password";
$mail->From = "email#domain.com";
$mail->FromName = "auto";
$mail->AddAddress("example#example.net", "Name of example user"); //send to....
$mail->IsHTML(true);
$mail->CharSet = "UTF-8";
$mail->Subject = "=?UTF-8?B?".base64_encode(stripslashes($asunto))."=?=";
$mail->Body = stripslashes($mensaje);
if(!$mail->Send()){
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
return true;
} else {
echo "Message has been sent";
return false;
}
Hope it helped :)
I am having an issue with getting my PHP mailer code to work correctly. I can get it to send an email on page load fine, the issue is with the ISSET command to get it to submit the form once the submit button has been pressed. I have tried putting it in various places but still can't get it to work. Any help would be appreciated.
<?php
require '/phpmailer/PHPMailerAutoload.php';
require_once '/phpmailer/class.phpmailer.php';
include '/phpmailer/class.smtp.php';
if(isset($_POST["Submit"]))
{
$emailaddress = '****#**********';
$message=
'Name: '.$_POST['name'].'<br />
Email: '.$_POST['email'].'<br />
IP: '.$_SERVER['REMOTE_ADDR'].'<br /><br />
Message:<br /><br />
'.nl2br($_POST['message']).'
';
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "********"; // SMTP server
$mail->SMTPDebug = 1; // 1 = errors and messages,2 = messages only
$mail->SMTPAuth = false; // enable SMTP authentication
$mail->Port = 25; // set the SMTP port for the GMAIL server
$mail->SMTPSecure = 'false'; // Enable encryption, 'ssl' also accepted
$mail->CharSet = 'UTF-8'; // so it interprets foreign characters
$mail->setFrom('***********');
$mail->AddReplyTo('**********');
$mail->Subject = "Contact form submission from ".$_POST['name']." ";
$mail->MsgHTML($message);
$mail->AddAddress($emailaddress);
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Thank you, your message has been sent!";
}
I'm going to make my comment as an answer, because that is the only conclusion I can come up with and the most likely to be, without seeing the OP's HTML form.
Your conditional statement if(isset($_POST["Submit"])) is based on a submit button named Submit. If your submit button has name="submit" instead of name="Submit", then that would explain it. If it isn't named, then do.
I.e.:
<input type="submit" name="Submit" value="Send Email">
is not the same as
<input type="submit" name="submit" value="Send Email">
POST variables are case-sensitive.
Your presently shown code has the proper bracing.
Having used error reporting and placed the top of your file(s) right after your opening <?php tag
error_reporting(E_ALL);
ini_set('display_errors', 1);
would have signaled an Undefined index Submit... warning message.
I have some PHP code that I'm using to send email to a specific e-mail address. However, I'd like to include a couple more e-mail addresses in the PHP for when it sends it.
when i tried it showing the following
ERROR:Mailer Error: You must provide at least one recipient email address.
code
include "class.phpmailer.php"; // include the class file name
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
//$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "mail.authsmtp.com";
$mail->Port = "25"; // or 587
$mail->IsHTML(true);
$mail->Username = "xxxxx";
$mail->Password = "xxxxx";
$mail->SetFrom("cpn#xxxxxxx.com");
$mail->Subject = $sub1;
$mail->Body = $text_mail;
$mail->AddAddress("xxxxxxx#gmail.com;aral#xxxxxx.com;akhader#xxxxxx.com");
if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}
else{
echo "Message has been sent";
}
any one guide me how to do it
Change this line
$mail->AddAddress("xxxxxxx#gmail.com;aral#xxxxxx.com;akhader#xxxxxx.com");
to this:
$mail->AddAddress("xxxxxxx#gmail.com");
$mail->AddAddress("aral#xxxxxx.com");
$mail->AddAddress("akhader#xxxxxx.com");
You can run that function as many times as you like until you've got all the addresses you need.
See Here for more info
It seems that you are miss using the AddAdress method. You should pass every mail separatly like that :
$mail->AddAddress("xxxxxxx#gmail.com");
$mail->AddAddress("aral#xxxxxx.com");
$mail->AddAddress("akhader#xxxxxx.com");
See PHPMailer AddAddress() for more details.
If you want to send email to multiple address, You need to call the AddAddress() function for each and every Email address. First parameter is EMAIL address, Second one is Recipient name and it is optional.
$mail->AddAddress("xxxxxxx#gmail.com", "XXXXXXXX");
$mail->AddAddress("aral#xxxxxx.com", "Aral");
Try this
$mail->AddAddress("xxxxxxx#gmail.com");
$mail->AddAddress("aral#xxxxxx.com");
$mail->AddAddress("akhader#xxxxxx.com");
Take a look here PHPMailer AddAddress()
and keep an eye of your line:
$mail->AddAddress("xxxxxxx#gmail.com;aral#xxxxxx.com;akhader#xxxxxx.com");
Instead of:
$mail->AddAddress("xxxxxxx#gmail.com;aral#xxxxxx.com;akhader#xxxxxx.com");
You should use
$mail->AddAddress('xxxxxxx#gmail.com', '1');
$mail->AddAddress('aral#xxxxxx.com', '2');
$mail->AddAddress('akhader#xxxxxx.com', '3');
Or use CC copies:
$mail->AddCC('xxxxxxx#gmail.com', '1');
$mail->AddCC('aral#xxxxxx.com', '2');
$mail->AddCC('akhader#xxxxxx.com', '3');
Try this.... This may help you
<html>
<body>
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail("chauhanamrish32#gmail.com,amrinderpuri1990#gmail.com,amrinder_puri#yahoo.com,amrindersinghpuri13#gmail.com", $subject,$message, "From:" . $email);
echo "Thank you for using our mail form";
}
else
//if "email" is not filled out, display the form
{
echo "<form method='post' action='mail.php'>
Email: <input name='email' type='text'><br>
Subject: <input name='subject' type='text'><br>
Message:<br>
<textarea name='message' rows='15' cols='40'>
</textarea><br>
<input type='submit'>
</form>";
}
?>
How to get user mails in my free gmail inbox through contact us form on my website. I do not use email with my website name . i use free gmail. I tried many script but the all need email account on domain.
Does this question have something to do with This One?
Well, so you have a form on your site, your users fill it up and you need an email with that data, right?
Simple example:
<form action="sendMail.php" method="post">
Name: <input type="text" name="name" id="name" /><br />
Email: <input type="text" name="email" id="email" /><br />
Text: <textarea name="text"></textarea><br />
<input type="submit" value="Send" />
</form>
then, the php page wich send the mail:
//php sendThis.php page
<?php
require("class.phpmailer.php");
$name = $_POST['name'];
$email = $_POST['email'];
$text = $name . ', ' . $email . ' has filled the form with the text:<br />' . $_POST['text'];
$from = 'your.email#gmail.com';
$to = 'your.email#gmail.com';
$gmailPass = 'your gmail password';
$mail = new PHPMailer();
$mail->IsSMTP();
// enable SMTP authentication
$mail->SMTPAuth = true;
// sets the prefix to the server
$mail->SMTPSecure = "ssl";
// sets GMAIL as the SMTP server
$mail->Host = 'smtp.gmail.com';
// set the SMTP port
$mail->Port = '465';
// GMAIL username
$mail->Username = $from;
// GMAIL password
$mail->Password = $gmailPass;
$mail->From = $from;
$mail->FromName = $from;
$mail->AddReplyTo($from, $from);
$mail->Subject = 'This is a test!';
$mail->Body = $text;
$mail->MsgHTML($text);
$mail->IsHTML(true);
$mail->AddAddress($to, $to);
if(!$mail->Send()){
echo $mail->ErrorInfo;
}else{
echo 'sent!';
$mail->ClearAddresses();
$mail->ClearAttachments();
}
?>
EDIT: just tested and works fine. Make sure that the 3 files (class.phpmailer.php, class.pop3.php and class.smtp.php) are in the correct include path
Basically, it involves the PHP mail() function:
<?php
mail(yourGmailAddress, object, message);
?>
As you have already observed, this solution works only if the webserver operates a mail server. This mail server may forbid unknown users. So you need to have an email account on that web/mail server (I believe this is the case). The second step then is to forward mail from your website address to you gmail account. I am 90% certain that it is possible from your gmail configuration. It may also be possible from your website mail configuration. But don't configure both!
Try enabling openssl.
Uncomment the line:
extension=php_openssl.dll
in your php.ini file.
You can also put your email address into "action" attribute of the form element. But that's very unreliable. Like this:
<form method='post' action='mailto:your#email.com?Subject=Hello'>
...
</form>
Users must have email client installed and configured for this to work properly. There are some other drawbacks. You have to do some research to find whether this method is for you or not.
http://www.google.com/search?client=opera&rls=en&q=form+action+mailto&sourceid=opera&ie=utf-8&oe=utf-8