PHP Contact Form, not sending email [duplicate] - php

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I have been trying to make my first contact form and after hours of googling I can't seem to find the error in my code why it's not working.
My php code:
<?php
$to = 'llavert#gmail.com';
$from = strip_tags($_POST['email']);
$name = strip_tags($_POST['name']);
$adress = strip_tags($_POST['address']);
$city = strip_tags($_POST['city']);
$subject = strip_tags($_POST["subject"]);
$message = strip_tags($_POST['message']);
$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, $header);
print_r(error_get_last());
?>
My html form:
<form method="post" action="mailer.php">
<input type="text" class="col-md-13 col-xs-12 name" name='name' placeholder='Naam *'/>
<input type="text" class="col-md-13 col-xs-12 Email" name='email' placeholder='Email *'/>
<input type="text" class="col-md-13 col-xs-12 name" name='address' placeholder='Straat en huisnummer *'/>
<input type="text" class="col-md-13 col-xs-12 Email" name='city' placeholder='Postcode en gemeente *'/>
<input type="text" class="col-md-12 col-xs-12 Subject" name='subject' placeholder='Onderwerp *'/>
<textarea type="text" class="col-md-12 col-xs-12 Message" name='message' placeholder='Bericht aan BDS bvba *'></textarea>
<div class="cBtn col-xs-12">
<ul>
<li class="clear"><i class="fa fa-times"></i>Formulier legen</li>
<li class="send" name="submit" type="submit" value="Send"><i class="fa fa-share"></i>Bericht sturen</a></li>
</ul>
<br><br><br><br><br><br><br><br><br>
</div>
</form>

From the manual
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.
It is most likely that your local mail server is not set up correctly.

Related

PHP code is sending emails to spam, how to prevent it? [duplicate]

This question already has answers here:
How do you make sure email you send programmatically is not automatically marked as spam?
(24 answers)
Closed 1 year ago.
I'm new to PHP and HTML working on a website both codes seem to be working.
I'm trying to edit an existing contact us form and send the form to a default email but it is getting to the spam folder.
Here is my HTML code part:
<div class="row-fluid">
<div class="span8" id="divMain">
<h1>Contact Us</h1>
<h3 style="color:#;"></h3>
<hr>
<!--Start Contact form -->
<form name="enq" action="contact-form-handler.php" method="POST" onsubmit="return validation();">
<fieldset>
<input type="text" name="name" id="name" value="" class="input-block-level" placeholder="Name" maxlength="80" />
<input type="text" name="email" id="email" value="" class="input-block-level" placeholder="Email" maxlength="80" />
<textarea rows="11" name="message" id="message" class="input-block-level" placeholder="Message" maxlength="1024"></textarea>
<div class="actions">
<input type="submit" value=" Send " name="submit" id="submitButton" class="btn btn-inverse pull-left" title="Click here to submit your message!" />
</div>
</fieldset>
</form>
<!--End Contact form -->
</div>
and here is my PHP code:
<?php
$name=$_POSt['name'];
$vistor_email=$_POST['email'];
$message=$_POST['message'];
$email_from='ex2#gmail.com';
$email_subject="New request to A-Akawi";
//$email_body="User Name:$name.\n"."User Email:$vistor_email.\n"."User message:$message.\n";
$body = <<<EMAIL
You have received a new request from $name with the following email address $vistor_email.
The following request is:
$message.
EMAIL;
$to ='ex1#gmail.com';
$headers .= "From: Johnson Smith <noreply#ksar.com> . \r\n" ;
$headers .='Reply-To: '. $to . "\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";
mail($to,$email_subject,$body,$headers);
header("location: contact.html");
?>
I'm getting it to the spam even after adding the headers how to fix it?
As far as I know you also need to add the Return-Path: to the header of your e-mail.
But there could be many more reasons why your email is going to the spam.
The spf records in your DNS could be configurate wrong or the IP of your server is listed in spam filters

Why is my php form data not being submited to my email [duplicate]

This question already has answers here:
How can I get useful error messages in PHP?
(41 answers)
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 2 years ago.
<?php
if (isset ($_POST['contact-form'])) {
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$msg = $_POST['message'];
// add the recipient email to a variable
$to = "myemail#gmail.com";
//create a subject
$subject = "$name sent you a message about a qoute";
//construct the message
$message = "Name: $name\r\n";
$message .= "Email: $email\r\n";
$message .= "Message: $name\r\n$msg";
$message = wordwrap($message,72);
//heading and info
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: $name <$email>\r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSMail-Priority: High\r\n\r\n";
//send email
mail($to, $subject, $message, $headers);
}
?>
The above code is the php code located inside of a .php file with the html in the php file as follows:
<form method="post" action="" id="estimate-form">
<div class="form-group">
<input type="text" class="form-control form control-sm" id="name" placeholder="Name">
<div class="form-group">
<input type="email" class="form-control form control-sm" id="email" placeholder="Email">
<div class="form-group">
<textarea type="textarea" class="form-control form control-lg" id="message" placeholder="Message"></textarea>
</div>
</div>
</div>
</div>
<input type="submit" name="contact-form" value="submit" class="btn btn-outline-light btn-block" style="margin-top:-10px;">
</div>
</div>
</form>
The issue I am having is that Upon submit I am not receiving an email and I can not figure out how to make this operational. Did I make a mistake or leave something out? NOTE: I edited my email out but in my actual code myemail = my actual email address that I left out for privacy!****
You have:
<input type="text" class="form-control form control-sm" id="name" placeholder="Name">
It and your other input fields needs the name attribute to be set:
<input name="name" type="text" class="form-control form control-sm" id="name" placeholder="Name">
<input name="email" type="text" class="form-control form control-sm" id="name" placeholder="Name">
<textarea name="message" type="textarea" class="form-control form control-lg" id="message" placeholder="Message"></textarea>

How can i solve the issue with mail [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 3 years ago.
Im trying to fix this issue for the past 3 days, but nothing is working..
I have a contact form and I wrote a php code to get the messages to my email.
Here is my contact form? [ I use bootstrap ]
<form class="col-lg-6" action="kontakt-confirmation.php" method="POST">
<div class="form-group">
<label>Namn <span id="mustdo">*</span></label>
<input id="namn" name="namn" class="form-control" type="text" aria-describedby="nameHint"
placeholder="Namn" required>
<small id="nameHint" class="form-text text-muted">Fyll i formuläret nedan så kontaktar vi
dig!!</small>
</div>
<div class="form-group">
<label>E-postadress <span id="mustdo">*</span></label>
<input id="email" name="email" class="form-control" type="email" placeholder="Din e-post" required>
</div>
<div class="form-group">
<label>Subject <span id="mustdo">*</span></label>
<input id="subject" class="form-control" type="text" placeholder="Your subject.." required>
</div>
<div class="form-group">
<label for="message">Meddelande <span id="mustdo">*</span></label>
<textarea id="message" name="message" class="form-control" rows="5" required></textarea>
</div>
<button type="submit" name="submit" class="btn btn-lg btn-outline-primary">Skicka</button>
</form>
Here is my PHP code:
<?php
if(isset($_POST)) {
$namn = $_POST['namn'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = '??????????';
$subject = 'Ticket!';
$message = "Namn: ".$namn."\n"."Email ".$email."\n"."Problem / Question: "."\n\n".$message;
$headers = "From: ".$email;
if(mail($to, $subject, $message, $headers)) {
echo "Thanks for contacting us!";
} else {
echo "Problem!";
}
}
?>
when I press on submit, i get the Problem message. What can i change to fix this?
thanks
Hope this resolves your answer to the question :)
if(isset($_POST)) {
$namn = $_POST['namn'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = '??????????';
$subject = 'Ticket!';
$message = "Namn: ".$namn."\n"."Email ".$email."\n"."Problem / Question: "."\n\n".$message;
$headers = "From: ".$email;
// Always set content-type when sending HTML email
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
if(mail($to, $subject, $message, $headers)) {
echo "Thanks for contacting us!";
} else {
echo "Problem!";
}
}

PHP - Form Submit Doesn't Work [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I created a form styled with bootstrap and followed a PHP tutorial on how to make the form functional (when info is filled an email to be send to a specified email) but it doesn't work.
I have read a lot of threads on Stackoverflow but couldn't find a solution.
I configured my php.ini file (I think correctly) and still the mail() function doesn't work.
Below is my code. I am an absolute beginner in PHP and I really appreciate your help!
<?php
function has_header_injection($str) {
return preg_match( "/[\r\n]/", $str );
}
if (isset($_POST['contact_submit'])){
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$msg = $_POST['message'];
if (has_header_injection($name)||($email)) {
die;
}
if ( !$name || !$email || !$message ) {
echo '<h2 class="success">All fields are required</h2> Try again';
}
$to = "example#email.com"; (this has my true email)
$subject = "$name sent you a message via example's contact form";
$message = "Name: $name\r\n";
$message .= "Email: $email\r\n";
$message .= "Message:\r\n$msg";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: $name <$email>\r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSMail-Priority: High\r\n\r\n";
mail($to, $subject, $message, $headers);
?>
<h2 class="success"> Thank you! Your project request is submitted. We will get back to you within 24 hours.</h2>
<p>« Go to home page</p>
<?php } else { ?>
<form action="" class="contact-form" id="contact-form" method="post" role="form">
<div class="form-group">
<label class="sr-only" for="name">Name</label>
<input type="text" class="form-control" id="name" name="name" required="" placeholder="Name">
</div>
<div class="form-group">
<label class="sr-only" for="email">Email</label>
<input type="email" class="form-control" id="email" name="email" required="" placeholder="Email">
</div>
<div class="form-group">
<textarea class="form-control" id="message" name="message" placeholder="Enter a brief description of your project" required=""></textarea>
</div>
<button type="submit" class="btn btn-custom" name="contact_submit">Send</button>
</form>
<?php } ?>
Are you working on localhost, if yes then email functionality is not going to work, put your code on server.

Is there anything wrong with the code in my form?

I'm using this tutorial to create a contact form for my site and it doesn't seem to be working. After I fill in my form and press submit, nothing happens. I would like to know whats wrong with it and how I can fix it.
This is my code:
HTML:
<form action="mail/contact.php" method="post">
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Name:</label><br />
<input type="text" name="name" id="name" class="form-control" placeholder="Name"/>
</div></div>
<br />
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Email:</label><br />
<input type="text" name="email" id="email" class="form-control" placeholder="Email"/>
</div></div>
<br />
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Message:</label>
<textarea name="message" rows="5" id="message" class="form-control" placeholder="Message"></textarea>
</div></div>
<br />
<input type="submit" name="submit" value="Submit" class="btn btn-success btn-lg"/>
</form>
PHP:
<?php
// from the form
$name = trim(strip_tags($_POST['name']));
$email = trim(strip_tags($_POST['email']));
$message = htmlentities($_POST['message']);
// set here
$subject = "Contact form submitted!";
$to = 'name#mail.com';
$body = <<<HTML
$message
HTML;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
// send the email
mail($to, $subject, $body, $headers);
// popup success
echo '<script language="javascript">';
echo 'alert("Your message has been sent!")';
echo '</script>';
?>
It's not a problem actually, you hace to change $to to $email in the email() method because the variable that has the email you want to send to is $email.
Your contact.php code will be:
<?php
// from the form
$name = trim(strip_tags($_POST['name']));
$email = trim(strip_tags($_POST['email']));
$message = htmlentities($_POST['message']);
// set here
$subject = "Contact form submitted!";
$body = <<<HTML
$message
HTML;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
// send the email
mail($email, $subject, $body, $headers);
// popup success
echo '<script language="javascript">';
echo 'alert("Your message has been sent!")';
echo '</script>';
?>
Another recommendation is to check this tutorial for a secure contact form.
Also you should check out this two php frameworks:
Symfony 2 Mail
Zend 2 Mail

Categories