php mail function not sending mail in html website [duplicate] - php

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 2 years ago.
i have a website which is built in HTML and PHP . now to send mail I have made a contact form which looks like the following:
<form class="" method="post" dat-email="" action="">
<input type="text" class="form-control" name="name" placeholder="Name" required>
<input type="text" class="form-control" name="email" placeholder="Email" required>
<textarea class="form-control" name="message" placeholder="Your Message" required></textarea>
<input name="submit" class="def-btn" type="submit" value="submit">
</form>
for the form to work I have added the following PHP mail function:
<?php
if(isset($_POST['submit'])){
$headers .= "Return-Path: The Sender <zubairnazer#gmail.com>\r\n";
$headers .= "From: The Sender <zubairnazer#gmail.com>\r\n";
$headers .= "Organization: Sender Organization\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n" ;
$to = "zubairnaze#gmail.com";
$from = $_POST['email'];
$first_name = $_POST['name'];
$last_name = $_POST['message'];
$subject = "The Nosh Bistro Contact";
$message = $first_name . " has sent the following message. " . "\n\n" . $last_name. "\n\n"."Email " .$from. "\n\n" ;
mail($to,$subject,$message,$headers);
echo "<script type='text/javascript'>alert('Message Sent Successfully!')</script>";
}
?>
before it was working fine when I used only one header, but now I added these many headers so that my mail doesn't goes to spam folder. but now the mail function is not sending mails to my gmail id and I am getting the following error:
Notice: Undefined variable: headers in /hermes/walnacweb05/walnacweb05aa/b185/as.moluguz/nosh/index.php on line 1785
can anyone please tell me what could be wrong here

Related

PHP mail function sending blank emails [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 3 years ago.
I have an HTML form that posts to a PHP mail function. For some reason it does not send the content anymore. The emails display "This email has no content." Am I missing something?
//HTML - Post method form.
<form class="form" id="form" action="submitform.php" method="post">
<h2 style="padding-top: 10px;">Contact Us</h2>
<input class="input" type="text" placeholder="Name" name="name"><br>
<input class="input" type="text" placeholder="E-Mail Address" name="email"><br>
<input class="input" type="text" placeholder="Phone #" name="phone"><br>
<textarea class="input" placeholder="Questions, Specifications, etc."
name="message</textarea>
<input class="inputButton" type="submit">
</form>
//PHP - Gets posted HTML input data and sends it to the email, formatted with \n
<?php
$to = 'example#example.com' ;
$subject = 'Inquiry' ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$phone = $_POST['phone'] ;
$message = $_POST['message'] ;
$message = "From: $name \nEmail: $email \nPhone: $phone \nMessage: $message \n";
$sent = mail ($to, $subject, $message) ;
if($sent == true) {
echo "<h3>Thank you for your inquiry.</h3>";
}else{
echo "<h3>Sorry, your message wasn't sent.</h3>;
}
?>
I've found defining headers, even if I just want default values, helps me get my mail delivered. I can't say this is what you need to do because your code looks like it should run successfully as is.
An example of setting the headers to (I believe) default values:
$to = $to_email;
$subject = $your_subject;
$message = $your_message;
$headers = "From: S.O.<no-reply#dontusethis.email>\r\n" .
"Reply-To: [can be nice, not needed of course]\r\n" .
"X-Mailer: PHP/" . phpversion();
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to,$subject,$message,$headers);

I have some error with php that opens blank page [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Reference - What does this error mean in PHP?
(38 answers)
How do I get PHP errors to display?
(27 answers)
Closed 3 years ago.
I'm having some difficulty getting my contact form working on my website. It opens a blank page and actually doesn't work at all. My code is below:
<form action="mail.php" method="post" class="comment-form">
<input name="name" type="text" placeholder="Your Name" required>
<input name="email" type="email" placeholder="Email">
<input type="url" placeholder="Website">
<textarea rows="4" placeholder="Messages"></textarea>
<input type="submit" value="send message">
</form>
And php code:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: Website';
$to = 'me#me.com';
$subject = 'Email Inquiry';
$header = "From: noreply#example.com\r\n";
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$header.= "X-Priority: 1\r\n";
mail($to, $subject, $message, $headers);
header("location: ../contact");
?>
Use this to send your cod to the php instead of just refreshing
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method='POST'>
There is nothing in your form with the name 'submit'. You have type="submit". So your code is not going in the if the condition of if($_POST['submit']).
You should check for something else. Like: if ($_POST['name']) or if ($_POST['email']).
Also, I would suggest having an else block for your - if ($_POST['name']) so you can show some message instead of getting a blank page.

PHP Undefined variable for HTML Form [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 5 years ago.
I am trying to run a contact form PHP script and HTML form and when I run it I get the following errors.
Notice: Undefined variable: name in /storage/ssd4/333/4197333/public_html/heros51/confirm.php on line 17
Notice: Undefined variable: p in /storage/ssd4/333/4197333/public_html/heros51/confirm.php on line 18
Notice: Undefined variable: message in /storage/ssd4/333/4197333/public_html/heros51/confirm.php on line 18
Notice: Undefined variable: visitor_email in /storage/ssd4/333/4197333/public_html/heros51/confirm.php on line 21
<form action="confirm.php" method="POST" >
<label>Name >></label><input id="name" type="text" /><br />
<label>Email >></label><input id="email" type="text" /><br />
<label>PRI >></label><input id="p" type="text" /><br />
<label>Message >></label><textarea id="message" rows="1"></textarea><br /><br /><br />
<input type="submit" value="submit" />
<a class="button" alt="" href="index.html">Cancel</a>
</form>
The PHP which is linked looks like this:
if( isset($_POST['name']) && isset($_POST['email']) && isset($_POST['p']) && isset($_POST['message']) ){
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$p = $_POST['p'];
$email_from = 'default03#securemail.com';
$email_subject = "New Form submission $name ";
$email_body = "You have received a new message from the user $p.\n". "Here is the message:\n $message".
$to = "erixom#gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
}
else
echo " ISSET FAIL";
$email_from = 'default03#securemail.com';
$email_subject = "New Form submission $name ";
$email_body = "You have received a new message from the user $p.\n". "Here is the message:\n $message".
$to = "test#gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
?>
instead of id="name" you must use name="name". The id attribute is used for JavaScript manipulation while the name attribute is used to name your POST variables
I would like to add that you should sanitize user submitted inputs. Even tho this might not be a internet facing project, it's never too early too adopt this as a habbit :)

PHP Form Processing ~ Issue with radio button chekced [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 7 years ago.
I am trying to make a contact form and I believe that the only way is through PHP (so I get an e-mail when my client contacts me.) It is really a very straightforward form, but I am cannot get the form to send me the radio button checked status and have no clue how.
This is my HTML:
<form action="contact.php" method="post">
Your name<br>
<input type="text" name="cf_name" ><br>
<br />
Your e-mail<br>
<input type="text" name="cf_email"><br>
<br />
Do you want to join my mailing list?<br>
<input type="radio" name="mail-list" value="yes">Yes<br>
<input type="radio" name="mail-list" value="no">No<br>
<input type="radio" name="mail-list" value="I_am_already_in_it">I am already in it<br>
<br />
Message<br>
<textarea name="cf_message" rows="10" cols="100">
</textarea><br>
<input type="submit" value="Send">
<input type="reset" value="Clear">
</form>
And this is my PHP:
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$radio_yes = $_POST ['yes'];
$radio_no = $_POST ['no'];
$radio_I_am_already_in_it = $_POST ['I_am_already_in_it'];
$mail_to = 'my-email#my-site.com';
$subject = 'Hello, I am contacting you from your site. My name is '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$body_message .= 'True: '.$radio_yes;
$body_message .= 'True: '.$radio_no;
$body_message .= 'True: '.$radio_I_am_already_in_it;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you very much. I will do my best to reply to you within 24 hours.');
window.location = 'contact.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('For some reason your message did not send. Please, do send me an e- mail directly to fernando#fernandoalbertmedium.com');
window.location = 'contact.html';
</script>
<?php
}
?>
The form is working fine, but the radio button status does not show up in the e-mail I receive. Also, for some reason, the cursor does not appear at the beginning of the textarea, but on the second line with some indent. Do you know why?
You are trying to get radio's value by value as $_POST's key, instead of this radio input's name, you need to get it like this:
$radio_value = $_POST['mail-list'];
$radio_checked = $_POST ['mail-list'];
their you get value which radio button is checked and $radio_checked value will become according to this as if you checked yes

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