php mail not receiving the message [duplicate] - php

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

Related

PHP email form does not send emails [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
HTML Form with Sendemail
(2 answers)
Closed 5 years ago.
I have only dabbled in PHP a little, I am trying to remember what I did last year. I am having trouble getting this to work - the user is redirected to index.php but then nothing happens. No email is recieved and no verification 'email sent/not sent' etc.
I am sure it is probably a silly mistake.
Any help would be appreciated.
contact.html
<form method="post" action="index.php">
<label>Name</label>
<input name="name" placeholder="Type Here">
<label>Email</label>
<input name="email" type="email" placeholder="Type Here">
<label>Message</label>
<textarea name="message" placeholder="Type Here"></textarea>
<label>*What is 2+2? (Anti-spam)</label>
<input name="human" placeholder="Type Here">
<input id="submit" name="submit" type="submit" value="Submit">
</form>
index.php
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = $_POST['email']; // GET EMAIL ADDRESS FROM FORM
$to = 'annie.palmer#outlook.com';
$subject = 'Website enquiry from' .$name;
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
$headers = "From: Annie<$from>\r\nReturn-path: $from" . "\r\n";
$headers .= "Content-type:text/text;charset=ISO-8859-1";
?>
<?php
if ($_POST['submit'] && ($_POST['human'] == '4') {
/* Anything that goes in here is only performed if the form is submitted */
if (mail ($to, $subject, $body, $headers, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
}
?>
I'm posting this as a community wiki; I don't feel any rep should come of this, nor do I want rep.
mail() uses 4 arguments, not 5.
http://php.net/manual/en/function.mail.php
There is a 5th but it doesn't do what you're expecting your 5th to do.
So remove the , $from from this:
if (mail ($to, $subject, $body, $headers, $from))
^^^^^^^
The From: belongs in the header and expects an email address.
Example from the manual:
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
Try using the PHPMailer. Once uploaded to your site sending an email is easy.
require ('../mail/PHPMailerAutoload.php');
require ('../mail/class.phpmailer.php');
//set up your email
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tbs'; //set as required
$mail->Host = "enter your email host here";
$mail->Port = 25;
$mail->Username = "enter your mail account username here";
$mail->Password = "enter your mail account password here";
$mail->From = "the from email address";
$mail->FromName = "the from name";
$mail->Subject = "the subject goes here";
$mail->IsHTML(true); //your choice
$body = "the body of you email - html or plain text";
$mail->Body = $body;
$mail->AddAddress("add the email address(es) of recipients");
$mail->Send();

Sending email with php and html form [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 learning php and I'm trying to send an email to myself using an html form but it doesn't works.
<form action="index.php" role="form" method="post" name="emailform">
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" id="email" name="email">
</div>
<div class="form-group">
<label for="comment">Text:</label>
<textarea type="textarea" class="form-control" id="textarea" rows="5" name="textarea"></textarea>
</div>
<button type="submit" class="btn btn-default" id="submit" name="submit">Submit</button>
</form>
<?php
function email()
{
$to = 'my_mail';
$message = $_POST['textarea'];
$from = $_POST['email'];
$subject = 'Portfolio';
$mail_headers = "From: " . $from . " <" . $from . ">\r\n";
$mail_headers .= "Reply-To: " . $from . "\r\n";
$mail_headers .= "X-Mailer: PHP/" . phpversion();
echo $to . " " . $message . " " . $from;
if(#mail($to, $subject, $message, $mail_headers))
echo #mail($to, $subject, $message, $mail_headers);
else echo "ERROR";
}
if(isset($_POST['submit']))
email();
?>
my_mail is my mail (I replaced it here but in the code there is my real email).
The code seem to work, in fact it display the echo #mail but the mail doesn't appear in my inbox
The code looks fine, but I think because of # in the mail function you are not seeing any errors. If you don't want to display error you can use it like this:
<?php
if(#mail($to, $subject, $message, $mail_headers)){
echo "Mail Sent!";
}else{
print_r(error_get_last());
}
?>
In this way the error is not thrown but you can use error_get_last() to see the error and log it if you want.
PS you are using mail function 2 times, so mail would be sent two times when it is going to work.
here is the correct way.
<form action="contact.php" etc... etc..>
blah blah blah
</form>
Then create a new php file (contact.php) and use the following
<?php
$field_name = $_POST["cname"];/* change " " according to your form */
$field_email = $_POST["cmail"];
$field_sub = $_POST["csub"];
$field_message = $_POST["cmsg"];
$to = "mailid1#mail.com, mailid2#mail.com";
$subject = " give subject" ;
$message = "message";
if(mail($to,$subject,$message))
{
echo "<script>alert('Your Message was sent Successfully. Thank You For Your Time !');</script>";
}
else
{
echo "<script>alert('Something wrong happened. Please try again later. Sorry For The Trouble'); </script>";
}
?>
<meta http-equiv="refresh" content="2; url=contact.html">
<!-- for coming back to intial page -->

PHP Mail not being received? [duplicate]

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;
}

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...

PHP email form CC

I have a very simple contact form on my site, Im looking for users to be able to just put a check mark next to "CC:" to have it CC them without creating a whole new field for that they have to fill out again.
Here is the HTML:
<form action="send.php" method="post" name="form1">
Name: <input name="name" size="35"><br/>
E-mail:<input name="email" size="35"><br/>
CC: <input input type="checkbox" name="mailcc"><br/>
Comment: <textarea cols="35" name="comment" rows="5"></textarea> <br />
<input name="Submit" type="submit" value="Submit">
</form>
And here is the PHP:
<?php
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$comment = $_REQUEST['comment'] ;
mail( "me#me.com", "Message Title", "Name: $name\n Email: $email\n Comments: $comment\n " );
echo "Message Sent! Thanks!"
?>
Ive been trying to add some items from this site:
http://w3mentor.com/learn/php-mysql-tutorials/php-email/send-email-with-cccarbon-copy-bccblind-carbon-copy/
But it wants to create a text field for CC which means the user would have to enter their email twice.
Ive also tried $mailheader.= "Cc: " . $email ."\n"; but I cant get that to work either.
Make the checkbox have a value (value="1") in HTML.
Add a variable ($mailheader) to the end of mail() function, as the last parameter.
So essentially:
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$comment = $_POST['comment'] ;
if ($_POST['mailcc'] == 1) {
$mailheader .= "CC: $name <$email>";
}
mail("me#me.com", "Message Title", "Name: $name\n Email: $email\n Comments: $comment\n ", $mailheader);
echo "Message Sent! Thanks!";
Is the Cc address you are testing with the same as the "to" address(me#me.com on your example)?
I did a quick test and with this code i get only one mail:
<?php
$to = "my#address.com";
$subject = "Testing";
$message = "Testing message";
$headers = "Cc: my#address.com";
mail($to, $subject, $message, $headers);
But with this i get a copy to my other email account:
<?php
$to = "my#address.com";
$subject = "Testing";
$message = "Testing message";
$headers = "Cc: my#otheraddress.com";
mail($to, $subject, $message, $headers);

Categories