PHP Mail not being received? [duplicate] - php

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Mail not being received by hotmail.com
I have this simple form on my site and I do not receive emails when it sends into my Hotmail account, not even the Junk folder.
Here is the form code:
<form action="mail.php" method="POST">
<p><label title="Name">Name:</label><br />
<input type="text" name="name" autocomplete="on" required="required"></p>
<p><label title="Email">Email:</label><br />
<input type="text" name="email" autocomplete="on" required="required"></p>
<p><label title="About">My message is about...</label><br />
<select name="about">
<option value="general">General Query</option>
<option value="wedding">Wedding</option>
<option value="corporate">Corporate Event or Trade Show</option>
<option value="other">Other Event</option>
</select>
<p><label title="Message">Message:</label><br />
<textarea name="message" rows="6" cols="25" required="required"></textarea></p>
<input type="submit" value="Send">
</form>
And the mail.php file:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$about = $_POST['about'];
$formcontent="From: $name \n About: $about \n Message: $message";
$recipient = "MyEmailAddress#Live.co.uk";
$subject = "Contact Form";
$mailheader = "Reply-To: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
I do end up seeing a page with "Thank you!" displayed but no email is received.

Mail delivery is a tricky business... just because you send mail does not mean that anyone will receive it. Many receiving servers will simply ignore the incoming message if it does not meet certain criteria (in my experience Gmail and Hotmail are particularly prone to just silently denying delivery, so it doesn't even end up in SPAM). There are a few things to make sure you've done:
1) You've set up PTR/SPF (reverse lookup) entries in your DNS records
2) Make sure that you're not on any blacklists (http://www.mxtoolbox.com/blacklists.aspx)
3) Expand your headers
$headers = "MIME-Version: 1.0\r\n"
."Content-Type: $contentType; charset=utf-8\r\n"
."Content-Transfer-Encoding: 8bit\r\n"
."From: =?UTF-8?B?". base64_encode("Your sending display name") ."?= <$from>\r\n"
."Reply-To: $replyTo\r\n"
."X-Mailer: PHP/". phpversion();
However, if you really want to ensure that mail gets through, send mail via SMTP. You can never guarantee mail delivery, but it will be much more reliable. If you're not sending a large volume of mail, you might try using Mandrill or similar service to relay emails for you.

You can use the following method. returns true on success.
function sendMail($email, $subject, $message)
{
$supportEmail = 'info#abc.com';
$from = 'Abc';
$msg = $message;
$from = str_replace(' ', '-', $from);
$frm = $from.' <'.$supportEmail.'>';
preg_match("<(.*)#(.*\..*)>", $frm, $match);
///////////////////Headers/////////////////
$hdr='';
$hdr.='MIME-Version: 1.0'."\n";
$hdr.='content-type: text/html; charset=iso-8859-1'."\n";
$hdr.="From: {$frm}\n";
$hdr.="Reply-To: {$frm}\n";
$hdr.="Message-ID: <".time()."#{$match[2]}>\n";
$hdr.='X-Mailer: PHP v'.phpversion();
$x=#mail($email, $subject, $msg, $hdr);
if($x==0)
{
$email=str_replace('#','\#', $email);
$hdr=str_replace('#','\#',$hdr);
$x=#mail($email, $subject, $msg, $hdr);
}
return $x;
}

Related

php mail not receiving the message [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I'm not receiving the text from the form field. Anything im doing wrong ?
<?php
$newsletter_email = $_POST['newsletter_email'];
$to = "gb#gyde.asia";
$subject = "Subscription for Newsletter";
$headers = "From: $to";
mail ($to, $subject, " E-mail: " . $newsletter_email, $headers);
if(mail ($to, $subject, " E-mail: " . $newsletter_email, $headers )){
echo "Mail did its job..."; } else { echo "Oops, something went South!"; }
?>
HTML
<div id="newsletter" class="form-wrap">
<form action="process.php" method="post" id="newsletter-form">
<input type="text" name="newsletter_email" id="newsletter_email" required class="feedback-input" maxlength="30" placeholder="Email" />
<input type="submit" name="newsletter_submit" id="newsletter_submit" value="Subscribe" class="button-blue"/>
</form>
</div>
Some time Mail function does not support your server. so mail can't reach.
There is a solutions please use SMTP mail.
<?php
ini_set("SMTP", "aspmx.l.google.com");
ini_set("sendmail_from", "YOURMAIL#gmail.com");
$message = "The mail message was sent with the following mail setting:\r\nSMTP = aspmx.l.google.com\r\nsmtp_port = 25\r\nsendmail_from = YourMail#address.com";
$headers = "From: YOURMAIL#gmail.com";
mail("Sending#provider.com", "Testing", $message, $headers);
echo "Check your email now....<BR/>";
?>
You scripts is fine, but you send mail twice.
Before send check if the POST have some message to send.
Change like this:
$newsletter_email = $_POST['newsletter_email'];
if($newsletter_email != ""){
$to = "gb#gyde.asia";
$subject = "Subscription for Newsletter";
$headers = "From: $to";
if(mail ($to, $subject, " E-mail: " . $newsletter_email, $headers ))
{
echo "Mail did its job...";
}
else
{
echo "Oops, something went South!";
}
}
N.B. Check your Spam Box as said Hanky Panky

HTML / PHP contact form doesn't send data to my gmail

i've been trying to fix this one with solutions i've found here and in other foruns but nothing seems to work. I'm really noob with PHP. I don't know if this info is relevant but i'm hosting my project at byethost.com which they say it supports PHP.
I have made a contact form in my HTML contact page, made a PHP file to process the data and send it to my gmail adress. It says message successfully sent, but the data never arrives at my inbox on gmail. I've tried changing the PHP code (with copy paste solutions) in alternative ways but with no luck. I've also tried to sent it to my hotmail account but it doesn't work either. Can anyone help me?
Here is the HTML contact form:
<div id="form_wrap">
<form method="post" action="form_process.php" id="contact_form" class="contact">
<label>
<span>NOME*</span>
<input name="nome" type="text" tabindex="1" required>
</label>
<label>
<span>E-MAIL*</span>
<input name="email" type="email" tabindex="2" required>
</label>
<label>
<span>TELEFONE*</span>
<input name="phone" type="tel" tabindex="3" required>
</label>
<label>
<span>WEBSITE</span>
<input name="website" placeholder="http://" type="url" tabindex="4">
</label>
<label>
<span>MOTIVO DE CONTACTO*</span>
<select class="escolha" name="motivo" size="1" tabindex="5" required>
<option>Contratá-lo</option>
<option>Fazer uma pergunta</option>
<option>Dizer olá ou agradecer</option>
</select>
</label>
<div>
<label>
<span>MENSAGEM*</span>
<textarea name="message" tabindex="6" required></textarea>
</label>
</div>
<div>
<input name="submit" type="submit" value="Enviar" id="submit">
</div>
</form>
<a class="subtop" href="#subtop">– Voltar ao topo</a>
</div>
Here is my form_process.php:
<?php
if(isset($_POST['submit'])) {
$nome = $_POST['nome'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$website = $_POST['website'];
$motivo = $_POST['motivo'];
$message = $_POST['message'];
$to = "mygmailadress#gmail.com";
$subject = "Site contact form";
$header = "From: ".$fromText."\r\n";
$header .= "Cc: ".$ccText."\n";
$header .= "Reply-To : ".$fromText."\r\n";
$header .= "Return-Path : ".$fromText."\r\n";
$header .= "X-Mailer: PHP\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/plain; charset=iso-8859-1\r\n";
mail($to, $subject, $header, $message, "From: " . $nome);
}
if(#mail($emailRecipient, $subject, $message, $headers))
{
echo "Mail Sent Successfully";
}else{
echo "Mail Not Sent";
}
?>
Why twice mail function?
mail has 4 parameters, you give 5 params (from is a paert of fourth, it should be in $header)
variable $emailRecipient used in your mail function doesn't exists.
in 'from' header should be an e-mail address (and name), not only a non-mail string
There are many possible reasons that the email never arrives.
It could be caught in spam, blocked by your host or your mail function could be incorrectly setup in your php.ini file.
However, from your code it looks like you are using the mail() function incorrectly.
You are trying to send the email twice by calling the function twice. Just call it once like:
if(mail(...)) {
echo 'good times';
} else {
echo 'boo, no email was sent';
}
Secondly you are using the function incorrectly. According to the documentation here the mail function takes five arguments like so:
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
$additional_headers and $additional_parameters are optional as denoted by the [square brackets]. $to, $subject and $message are required in that order.
Thirdly I heavily suggest NOT using the built in mail() function.
I suggest using SwiftMailer. It's a fully comprehensive PHP library which will look after you.
U are trying to send mail twice you are using wrong variable names.
This code works for me.
<?php
if(isset($_POST['submit'])) {
$nome = $_POST['nome'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$website = $_POST['website'];
$motivo = $_POST['motivo'];
$message = $_POST['message'];
$to = "asdf#gmail.com";
$subject = "Site contact form";
$header = "From: ".$email."\r\n";
$header .= "Cc: ".$email."\n";
$header .= "Reply-To : ".$email."\r\n";
$header .= "Return-Path : ".$email."\r\n";
$header .= "X-Mailer: PHP\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/plain; charset=iso-8859-1\r\n";
if(mail($to, $subject, $message, $header))
{
echo "Mail Sent Successfully";
}else{
echo "Mail Not Sent";
}
}
?>
If you are usinf free hosting, they probably restrict your ability to send email.
Something like that is happening:
https://www.freehosting.com/client/knowledgebase.php?action=displayarticle&id=25
PHP mailing functionality is limited on free account to prevent abuse. To make it working, your mailing script should be configured to use SMTP server 'cpanel.freehosting.com' and to authenticate against it using credentials of email account set up in cpanel.
Paid accounts are provided with unrestricted access to PHP mailing functionality.
You can find more info on setting up email authentication in PHP scripts at this link:
http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm
Optionally, PHP mail() can be enabled by purchasing corresponding addon HERE.

PHP Form doesn't work

My contact form doesn't work. Emails are not being sent.
Webpage Code :
<!--Form Start-->
<form method="post" action="sendmail.php">
Email: <input name="email" type="text"><br>
Message:<br>
<textarea name="message" rows="15" cols="40"></textarea><br>
<input type="submit">
</form>
<!--Form End-->
PHP Script :
<?php
$to = "oxydyzestudios#gmail.com";
$subject = "Comment";
$email = $_REQUEST['email'];
$message = $_REQUEST['message'];
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers);
if($sent) {
print "Your mail was sent successfully";
} else {
print "We encountered an error sending your mail";
}
?>
Yes, the email is correct.
Live Demo : http://unitedasone.web1337.net/form.html
Any help would be appreciated.
There's nothing wrong with your code and it reports success.
This is likely a problem with your mail set up on your server, if you're seeing Your mail was sent successfully then php's mail function has successfully passed the mail to the server for delivery.
From php.net:
It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.
How is mail sent on your server?

Contact form. How do I get the name along with the email?

It's my first time trying to make a contactform. And I've got a few problems
It's works, I get the email, but I don't get the name the name field with me in the email.
HTML:
<form method="post" name="contactform" action="scripts/contact.php">
<h3>Name</h3>
<input type="text" name="name">
<h3>Email Address</h3>
<input type="text" name="email">
<h3>Message</h3>
<textarea name="message"></textarea>
<br/><input class="submit" type="submit" value="Send Form">
</form>
PHP:
<?php
$to = "name#domane.com";
$subject = "Contact Us";
$name = $_POST['name'];
$email = $_POST['email'] ;
$message = $_POST['message'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $name, $headers) ;
if($sent)
{print "Your mail was sent successfully"; }
else
{print "One of the field are not filled as requirred"; }
?>
$name is my problem. I've I have it in, the email comes from hostmaster#domane.com, If I delete it, everything works fine. But I wan't the name to be sent to me. How?
Or should I do it completely different?
Also, if you leave all the fields blank, the "user" doesn't get any error message, and a blank email is sent to me.
Hope you can help me. :)
Michael Berkowski is correct. What you'll need to do is add the name to your message's body (not in the sense of the input name= attribute, rather the body of the email).
Something like this:
<?php
$to = "name#domane.com";
$subject = "Contact Us";
$name = $_POST['name'];
$email = $_POST['email'] ;
$message = $_POST['message'] ;
$headers = "From: $email";
$body = "Name: $name\r\n";
$body .= "Message: $message";
$sent = mail($to, $subject, $body, $headers) ;
if($sent)
{print "Your mail was sent successfully"; }
else
{print "One of the field are not filled as requirred"; }
?>
Revised:
HTML:
<form method="post" name="contactform" action="scripts/contact.php">
<label for="name">Name</label>
<input type="text" name="name" id="name" />
<label for="email">Email Address</label>
<input type="text" name="email" id="email" />
<label for="message">Message</label>
<textarea name="message" id="message"></textarea>
<br/><input class="submit" type="submit" value="Send Form" />
</form>
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'] ;
$message = $_POST['message'] ;
$body = "Name: $name\r\n";
$body .= "Message: $message";
$to = "name#domane.com";
$from = "automailer#mydomainname.com (Website Automailer)";
$subject = "Contact Us";
$headers = "From: $from\r\n" .
"Reply-To: $email ($name)";
$sent = mail($to, $subject, $body, $headers) ;
if($sent) { echo "Your mail was sent successfully"; }
else { echo "One of the field are not filled as requirred"; }
?>
You should read the mail function documentation on php.net.
Have a look at the function signature:
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
Now you're placing $name as the "$additional_headers" argument. You should pass $name and any extra relevant data in a $message argument instead.
Having that said, here's the correct code to send a message:
$sent = mail($to, $subject, "A message from $name: $message", $headers);
You should read more about how email messages are constructed. Instead of just putting a user defined message in there you probably want to specify some email headers, containing a more beautiful FROM: and the like...

Simple PHP Email form not working

Very simple email form code. Worked once, but won't work anymore, even at different addresses. That is to say the emails no longer show up, but I'm not erroring out eather.
<form action="/mail-us.php" method="POST">
<p>Name</p> <input type="text" name="name">
<p>Email</p> <input type="text" name="email">
<p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br />
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>
And here is the PHP
<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "blah#x-matic.net";
$subject = "X-Matic Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error sending email!");
?>
Note, I tested the email out with my gmail account (from gmail to email, instead of from form to email) and it worked.
Use SMTP mail when in localhost, and switch to mail() once the site is in a webserver (i.e your webhost)
At least that is what i do.
Unless you want to install Pegasus Mail on your computer, the mail() function will not work on your localhost computer, as your computer does not have a mail server installed.
Either that, or use SMTP.
if(isset($_POST['submit']))
{
$to = "xxx#google.com";
$subject = "Email from Sender; // quotation marks end ;
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
mail($to, $subject, $body);
}
else
{
echo "Mail sending Failure!";
}
?>
try this

Categories