Not getting any email from PHP contact form [duplicate] - php

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 4 years ago.
So I am creating a simple website and on the "contact us" page I have put a contact form that is supposed to mail the message there. The form actually gives a success message that the email is sent but I'm not getting any. I have checked the spam/junk folder as well. I tested this on apache local server. (My email is correct. I've stated it like that on the code here for privacy issues.)
Can I please have some insight on what I am missing since I am fairly new to coding?
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Mesazhi u dergua!'
);
$name = #trim(stripslashes($_POST['emri']));
$email = #trim(stripslashes($_POST['email']));
$phoneno = #trim(stripslashes($_POST['telefon']));
$message = #trim(stripslashes($_POST['mesazhi']));
$email_from = $email;
$email_to = 'name.surname#mail.net';
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Phone NO: ' . $phoneno . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
?>
<div class="contact-form">
<form action="sendemail.php" name="contact-form" method="post">
<input type="text" name="emri" placeholder="Emri" />
<input type="email" name="email" placeholder="Email" />
<input type="tel" name="telefon" placeholder="Nr Telefoni"/>
<textarea name="text" id="text" rows="8" placeholder="Teksti" name="mesazhi"></textarea>
<input type="submit" class="btn-send" value="Dergo">
</form>
</div>

Use this code mail($email_to, $subject, $body, 'From: <'.$email_from.'>');

you are using a # on each function call. Remove them and you will maybe see where the problem is.

Related

I'm not able to send messages using the mail() PHP function [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 able to find the error in my code. My PHP code is in my index.html file. I'm not able to send messages from my static webpage.
HTML Code:
<div class="col-md-6">
<form action="index.html" method="POST" class="contact-form" role="form">
<input type="text" class="form-control" id="fname" name="fname" placeholder="Your Full Name">
<input type="email" class="form-control" id="email" name="email" placeholder="Your E-mail">
<input type="text" class="form-control" id="subj" name="subj" placeholder="Your Subject">
<textarea id="mssg" name="mssg" placeholder="Your Message" class="form-control" rows="10"></textarea>
<input class="btn btn-main btn-lg" type="submit" id="submit" name="submit" data-loading-text="<i class='fa fa-spinner fa-spin'></i> Sending...">
</form>
</div>
PHP Code:
<?php
if (isset($_POST['submit'])) {
$to = 'email#company.com';
$siteName = 'http://www.website.com';
$name = $_POST['fname'];
$mail = $_POST['email'];
$subject = $_POST['subj'];
$message = $_POST['mssg'];
$mailSub = '[Contact] [' . $siteName . '] '.$subject;
$body = 'Sender Name: ' . $name . "\n\n";
$body .= 'Sender Mail: ' . $mail . "\n\n";
$body .= 'Message Subject: ' . $subject . "\n\n";
$body .= 'Message: ' . $message;
$header = 'From: ' . $mail . "\r\n";
$header .= 'To: ' . $to . "\r\n";
mail($to, $mailSub, $body, $header);
}else{
echo '0';
}
?>
I receive an error every time i try to send a message through my website. Thank you!
Looking at action="index.html" could be a problem if you did not instruct your system to treat .html files as PHP.
If not, then you will need to change it to a .php file extension and renaming your present file to accomodate it. Then change your action value to direct to that file.
For example:
<form action="script.php" method="post">
script.php being your present PHP handler.

Mail Form PHP Not Working [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I been spending hours and still can't figure it out. New to PHP mail form coding. Any help would truly be appreciated! Two images below: the html and php. Pretty simple setup. I get the echo 'thank you!!' message after clicking send button, but I still don't receive any emails at all.
HTML Form:
<form action="assetslphplmail.php" method="POST">
<input placeholder="NAME" type="text" name="name">
<input p1aceholder="EMAIL" type="email" name="email">
<input p1aceholder="TELEPHONE" type="te1" name="te1">
<input p1aceholder="SUBJECT" type="text" name="subjectline">
<textarea p1aceholder="COMMENT" name="message" rows="6" cols="25" </textarea>
<input c1ass="send_button" type="submit" value="SEND">
</form>
PHP Code:
$subject1ine = $_REQUEST['subject1ine'];
$name = $_REQUEST['name'];
$emai1 = $_REQUEST['emai1'];
$tel 1' $_REQUEST['teI'];
$message = $_REQUEST['message'];
$to = "jondergmai1.com";
mail ( $to, $subjectline, $name, $emai1, $tel, $message);
echo 'Thank you!!';
Replace your PHP code with following:
<?php
$subject = $_REQUEST['subjectline'];
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$tel = $_REQUEST['tel'];
$message = $_REQUEST['message'];
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To:'.$email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$to = "jonder#gmail.com";
mail($to, $subject, $message, $headers);
echo 'Thank you!!';
?>
Edit From and Reply-To part.
Here are the plenty of similar answers: PHP Mail form doesn't send email

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

Simple subscriber email form - PHP/HTML [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I am trying to create a simples subscriber email form , where one user inserts his email, and me and the client should receive a e-mail.
Email to me saying that got a new subscription.
Email to client saying that we will contact him shortly.
I know very little about php, i ask for help about what is wrong on this code and how to make it better in order to make what i want.
HTML:
<div class="mail2">
<!-- Subscription Form -->
<form action="form/form.php" method="post">
<h1>Try Now!</h1>
<input name="email" class="email" type="text" placeholder="Enter your email address ...">
Get started for free
<a class="top" href="#top">Top</a>
</form>
</div>
PHP:
<?php
$to = "office#site.com";
$from = "no-reply#site.com";
$headers = "From: " . $from . "\r\n";
$subject = "New subscription";
$body = "New user subscription: " . $_POST['email'];
if( filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) )
{
if (mail($to, $subject, $body, $headers, "-f " . $from))
{
echo 'Your e-mail (' . $_POST['email'] . ') has been added to our mailing list!';
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
Edit your html code..
<div class="mail2">
<!-- Subscription Form -->
<form action="form/form.php" method="post">
<h1>Try Now!</h1>
<input name="email" class="email" type="text" placeholder="Enter your email address ...">
<input type="submit" value="Get started for free">
<a class="top" href="#top">Top</a>
</form>
</div>
I would have to say first your HTML has an issue. With the Get started now. You're not actually submitting the form, you're just linking back to the page you're on.
So first change the HTML:
<div class="mail2">
<!-- Subscription Form -->
<form action="form/form.php" method="post">
<h1>Try Now!</h1>
<input name="email" class="email" type="text" placeholder="Enter your email address ...">
Get started for free
<a class="top" href="#top">Top</a>
</form>
</div>
Secondly, here's a neater version of the PHP with some improvements.
$to = "office#site.com";
$from = "no-reply#site.com";
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: " . $from;
$headers[] = "Reply-To: " . $from;
$headers[] = "X-Mailer: PHP/".phpversion();
$subject = "New subscription";
$body = "New user subscription: " . $_POST['email'];
if( filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) )
{
if (mail($to, $subject, $body, implode("\r\n", $headers)))
{
echo 'Your e-mail (' . $_POST['email'] . ') has been added to our mailing list!';
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
If the rest doesn't work, make sure that sendmail is installed and setup correctly on the server.
Just to point out that if the mail check returns false it might not specifically be the e-mail that's at fault as your output error message suggests.

Sending and Receiving mail through php contact form [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 8 years ago.
Recently, I have purchased a domain and hosting. I've also created a webpage having contact form in it. I want when the user wrote something in textarea of contact form and clicks submit then that message is sended to my gmail account and so that i can reply also to those messages. I've also used this script to do so but its not working.
This is sendemail.php file
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Thank you for contact us. As early as possible we will contact you '
);
$name = #trim(stripslashes($_POST['name']));
$email = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'raunakhajela#gmail.com';//replace with your email
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
This is my contact form code in index.php
<div class="contact" id="contact">
<div class="container-3x">
<div class="block-header"> <!-- Blocks Header -->
<h2 class="title">Contact Us</h2>
</div>
<div class="block-content"> <!-- Blocks Content -->
<form action="sendemailphp" method="post" class="trigger-form-animate">
<input type="text" value="" id="name" name="name" placeholder="Name *" />
<input type="text" value="" id="email" name="email" placeholder="Email *" />
<input type="text" value="" id="website" name="website" placeholder="Website *" />
<textarea type="text" value="" id="message" name="message" rows="3" placeholder="Your Message *" ></textarea>
<div class="clr"></div>
<button>Submit Message</button>
</form>
</div>
</div>
</div>
I've also tried "http://www.mybloggertricks.com/2012/06/connect-your-website-email-address-to.html" this tutorial but its not working. Unable to find "Send through Gmail (easier to set up)" this option in gmail on adding another accounts windoww.
How can i do that?? Plzz hlp
You don't have a named subject form element which may explain why mail is failing and may very well be sent to Spam instead.
For example: <input type="text" name="subject">. Either add one of replace.
You will however need to make sure that this is filled out using a conditional statement
(see further below for an example).
$subject = #trim(stripslashes($_POST['subject']));
with
$subject = "Form submission";
You could also add this instead to your form:
<input type="hidden" name="subject" value="Form submission">
Either this or what I've outlined just above will work.
Many Email clients will either send mail to Spam or reject it altogether if a "subject" is missing, which is clearly missing from your code.
Checking if subject has been filled example:
if(isset($_POST['subject']) && !empty($_POST['subject'])){
// do someting
}
try this,both will work
<?php
$to = "usermailid#gmail.com";
$subject = "Welcome to";
$message = " Hi $username,<br /><br />
Thank you for signing up with us.<br />
Thanks <br />";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: <yourmailid#gmail.com>' . "\r\n";
$mail=mail($to,$subject,$message,$headers);
if($mail)
{
$to = "admin#gmail.com";
$subject = "Following Customer Signed Up";
$message = " $username,Customer is signed up with us,<br /><br />
Customer Details:<br />First Name:$firstname<br/>Last Name:$lastname<br/>Email:$email<br/>
Phone:$phone<br/>Zip Code:$zip<br/>Message:$message_cust<br/><br/><br/>
Thanks <br />";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: <yourmailid#gmail.com>' . "\r\n";
$mail=mail($to,$subject,$message,$headers);
}
?>

Categories