I can not receive from php mail function [duplicate] - php

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 :)

Related

PHP mail() function not working despite confirmation [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I have created a form that allows people to send an email from a website. The HTML code (see attached) calls a PHP script (see attached), and the email is supposed to be sent. The webpage displays the message "Email successfully sent", but I never actually received the email (it's not in spam either).
I have reached out to my hosting service (awaiting reply) to check whether PHP is supported or not. In the meantime, I would like to ensure that my code has no errors.
HTML:
<form action="message.php" method="post">
<fieldset>
<p>Name <span class="requiredAsterisk">*</span></p>
<input name="name"/>
<p>Email <span class="requiredAsterisk">*</span></p>
<input name="email"/>
<p>Message <span class="requiredAsterisk">*</span></p>
<textarea name="message"></textarea>
</fieldset>
<fieldset>
<input class="sendMessage w3-large" type="submit" value="Send Message"/>
</fieldset>
</form>
PHP:
<?php
$header = 'From: ' .$_POST['name'] ."\r\n" .'Reply-to: ' .$_POST['email'] ."\r\n" .'X-Mailer: PHP/' .phpversion();
if (mail("email#mail.com", "Email from website", $_POST['message'], $header)) {
echo ("<p>Email successfully sent</p>");
} else {
echo ("<p>Email failed</p>");
}
?>
Thanks in advance
A good alternative to the original mail() function in PHP would be something like PHPMailer. As stated in the github page:
the vast majority of code that you'll find online that uses the mail()
function directly is just plain wrong! Please don't be tempted to do
it yourself - if you don't use PHPMailer, there are many other
excellent libraries that you should look at before rolling your own -
try SwiftMailer, Zend_Mail, eZcomponents etc.
PHPMailer is super easy to set up and get going. This is the basic syntax to send an email:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('from#example.com', 'Mailer');
$mail->addAddress('joe#example.net'); // Add a recipient
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
(I would probably comment this, but my rep is too low) You should use
$message = wordwrap($_POST['message'], 70, "\r\n"); so your message follows the documentation on mail(). Besides this, your code seems to be fine. As you mentioned, it is probably related to your hosting provider, as it is common place for them to block the mail function. Also see this question on it for some extras which may the cause of your problem.

Issues in mail received time when using hotmail in php mailer

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

PHPMailer With Attachment Never Received

I am tying to send an email with an attachment using phpmailer.
include_once('/home/site/PHPMailer/class.phpmailer.php');
$mail = new PHPMailer();
$body = $mail->getFile('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.free.fr"; // SMTP server
$mail->IsSendmail(); // telling the class to use SendMail transport
$mail->From = "name#sub.fr";
$mail->FromName = "name";
$mail->Subject = "subject";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAddress("sub#sub.net", "name");
$mail->AddAttachment("mylist.csv"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
I receive a "Message sent !" on execution, but no email is ever received.
It is very possible the user you sent the email to did not recieve it due to the fact a lot of mail providers such as AOL and Yahoo block massive amounts of Ip addresses related to email spam. So if the server you are running this php script from is on their blacklist the user will not even receive it to the spam folder.
Check your php email logs.
http://help.yahoo.com/l/us/yahoo/smallbusiness/webhosting/php/php-03.html
Also, if this is not the case, try making sure the file your trying to include exists, and you are passing the correct path to the file. Like #Waygood said, try seeing if it sends without the attachment.

Sending an email via php mailer I get "myemail via host.blabla" in sender, how to remove that?

I have this phpmailer which is blasting emails and when recieving the email the sender is : myemail#myemail.com via web258.opentransfer.com (my host)
thats my code:
// Real Email Blast:
$mail = new PHPMailer();
$mail->From = "myemail#email.com";
$mail->FromName = "myname";
$mail->AddAddress($email, $name);
$mail->Subject = $htmlTitle = stripslashes($reSubject);
$mail->Body = $htmlBody = "
<div style='direction: rtl; text-align: right;'>
".stripslashes($reEmailContents)."
</div>";
// Setting plain text:
$text_body = $htmlTitle."
".strip_tags($htmlBody);
$mail->AltBody = $text_body;
if (!$mail->Send()) {
// Email failed error, resending user to landing page:
$error .= "<span style='color: #D20005;'>- Failed sending email to: ".$email." (".$name.")</span><br>";
}
that's especially visible on outlook and on gmail when you access the email itself you can see it on the sender box - how can I remove this and send without the host?
That's the intention of the "via yourdomainhere.com"
I don't believe you can change it, unless you run a custom mail server on your site (which may not be possible on a shared host)
Irregardless, your question would probably be better suited for ServerFault since PHPMailer isn't the issue.

How to get user mails in my free gmail inbox through contact us form on my website

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

Categories