I'm having some problems with my contact page.
Here are the parts:
<form method="post" action="mail.php">
<input name="nome" type="text" style="width: 265px;" placeholder="Nome e Cognome">
<input name="mail" type="email" style="width: 263px;" placeholder="E-mail">
<textarea name="messaggio" placeholder="Messaggio"></textarea>
<button type="submit" name="invia" style="margin-left: 0; margin-top: 10px;">Invia</button>
</form>
and..
<?php
$to = "mail";
$subject = "Modulo proveniente dal sito www.miosito.it";
$body = "Contenuto del modulo:\n\n";
$body .= "Nome: " . trim(stripslashes($_POST["nome"])) . "\n";
$body .= "Email: " . trim(stripslashes($_POST["mail"])) . "\n";
$body .= "Messaggio: " . trim(stripslashes($_POST["messaggio"])) . "\n";
$headers = "From: Valle srl <info#vallesrl.com>";
"Content-Type: text/html; charset=iso-8859-1\n";
if(#mail($to, $subject, $body, $headers)) {
header("Location: http://www.alessandrogiordano.me/test/valle02/sent.php");
} else {
header("Location: http://www.alessandrogiordano.me/test/valle02/nosent.php");
}
?>
First of all.. if I click on the submit button with all blank the email is sent blank.
Even if I make some errors and I get the else message the email is sent.. blank obviously.
I'm going crazy.. I'm making this website for free for a friend but I'm a graphic designer not a web developer. Never again! :D
Help!! Thank you very much.
put this line in your headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Before sending mail you have to validate all the fields whether they are empty or not
Like this
if( trim($_POST["nome"]) != "" )
{
// send mail
$isMailSend = mail($to, $subject, $body, $headers);
}
{
//show error
}
if( $isMailSend ) {
header("Location: http://www.alessandrogiordano.me/test/valle02/sent.php");
} else {
header("Location: http://www.alessandrogiordano.me/test/valle02/nosent.php");
}
This
$headers = "From: Valle srl <info#vallesrl.com>";
"Content-Type: text/html; charset=iso-8859-1\n";
Should be,
$headers = "From: Valle srl <info#vallesrl.com>";
$headers. = "Content-Type: text/html; charset=iso-8859-1\n";
you can't use type="email",there should be type="text"
Related
Recently I've been having problems with my PHP contact form. It's worked great for about two years, and I haven't changed anything, so I don't really understand what the problem is. Here's the code:
<?php
// Check for header injections
function has_header_injection($str) {
return preg_match ( "/[\r\n]/", $str );
}
if(isset ($_POST['contact_submit'])) {
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$tel = trim($_POST['tel']);
$msg = $_POST['message'];
// check to see if name or email have header injections
if (has_header_injection($name) || has_header_injection($email)){
die();
}
if ( !$name || !$email || !$msg ) {
echo '<h4 class="error">All Fields Required</h4>Go back and try again';
exit;
}
// add the recipient email to a variable
$to = "example#example.net";
// Create a subject
$subject = "$name sent you an email";
// construct your message
$message .= "Name: $name sent you an email\r\n";
$message .= "Telephone: $tel\r\n";
$message .= "Email: $email\r\n\r\n";
$message .= "Message:\r\n$msg";
$message = wordwrap(message, 72);
// set the mail header
$headers = "MIME=Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "\r\nFrom: " . $name . " \r\n\r\n" . $tel . " \r\n\r\n " . $msg . "\r\n\r\n <" . $email . "> \r\n\r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSMail-Priority: high\r\n\r\n";
// Send the Email
mail( $to, $subject, $message, $headers );
?>
<!--- END PHP CONTACT FORM -->
<!-- Show Success message -->
<h2>Thanks for contacting Us!</h2>
<p align="center">Please allow 24 hours for a response</p>
<p>« Go to Home Page</p>
<?php } else { ?>
<form method="post" action="" id="contact-form">
<label for="name">Your Name</label>
<input type="text" id="name" name="name">
<label for="tel">Your Phone Number</label>
<input type="tel" id="tel" name="tel">
<label for="email">Your Email</label>
<input type="email" id="email" name="email">
<label for="message">the date/time you wish to sign up for</label>
<textarea id="message" name="message"></textarea>
<br>
<input type="submit" class="button next" name="contact_submit" value="Sign Up">
</form>
<?php } ?>
However, when the contact form is submitted, instead of sending the information to the body of the email, it sends it in the "From" section of the email. For example, the email might say:
To: Web Developer
From: Bob Smith 888-888-8888 mondays, wednesdays fridays
Subject: Bob Smith sent you an email!
Body:
X-Priority: 1X-MSMail-Priority: high
message
I don't really know what's going on, so any help would be appreciated!
You are adding all that info in the "from" header.
$headers .= "\r\nFrom: " . $name . " \r\n\r\n" . $tel . " \r\n\r\n " . $msg . "\r\n\r\n <" . $email . "> \r\n\r\n";
Change your headers to this:
$headers = "MIME=Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: {$name} <{$email}>\r\n"; // Removed all extra variables
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSMail-Priority: high\r\n";
and it should work.
You are already sending the $message, containing all the above data in the body as well.
Why you haven't experienced this before is however a mystery.
NOTE: You only need to have one \r\n after each header.
You should also change this row:
$message = wordwrap(message, 72);
to
$message = wordwrap($message, 72); // Adding $ in front of the variable.
I am not good at PHP but still trying to create a test script so that i can learn it. I am referring to w3schools and i don't know how good or bad i am.
I need some changes to be made to what script i just created.
<?php
$to = $_POST['EmailList'];
$subject = $_POST['EmailSubject'];
$message = $_POST['EmailBody'];
// 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";
// More headers
$headers .= 'From: <admin#admin.com>' . "\r\n";
mail($to,$subject,$message,$headers);
print_r($headers)
?>
<html>
<center>
<form method="post">
<br><strong>PHP Email Sender</strong><br><br><br>
Email List<br>
<textarea name="EmailList" placeholder="email#email.com (New Email Each Line)" rows="20" cols="50"></textarea><br><br>
Subject<br>
<input type="text" name="EmailSubject" placeholder="Your Subject Goes Here"><br><br>
Body<br>
<textarea name="EmailBody" placeholder="Write your content (HTML Accepted)" rows="20" cols="50"></textarea><br><br>
<input type="submit" value="Submit!">
</form><br><br>
</center>
</html>
I want some help so that i can send email's to different email's but each email would be in a different line and i would not be using a comma(,). I want the script to generate the comma(,) by its own and carry each email from a new line.
For example i entered 10 emails i need each email to be printed and a message saying sent besides that.
Please let me know if this is possible. I just need some help.
This is tested:
<?php
$subject = $_POST['EmailSubject'];
$message = $_POST['EmailBody'];
// 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";
// More headers
$headers .= 'From: <admin#admin.com>' . "\r\n";
$emailList = explode("\n",$_POST['EmailList']);
if(count($emailList) > 0){
foreach($emailList as $to){
$to = trim($to);
$sent = mail($to,$subject,$message,$headers);
if ($sent){
echo "<p>Sent: $to</p>";
}
else{
echo "<p>Not Sent: $to</p>";
}
}
}
else{
echo "<p>No email addresses</p>";
}
print_r($headers);
?>
Sorry folks, but I think I have a little problem (easy to solve) but I am not getting the solution by myself. Could you help me out?
The problem I am facing is this:
- the PHP script (handled by PHP mailer) is sending an e-mail, but not the information people fill in at the form.
Here is the php script I use:
<?php
$to = "user#domain.com";
$subject = "Request";
$message = "<h1>Request</h1>";
$message .= "<strong>street</strong>: $_POST['street']";
$message .= "<strong>store</strong>: $_POST['store']";
$headers = "From: request#domain.com";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html\r\n";
$sent = mail($to, $subject, $message, $headers);
if( $sent = mail($to, $subject, $message, $headers) ){ echo "SENT"; } else { echo "There
was a problem"; }
?>
Thanks in advance!
<?php
$to = "user#domain.com";
$subject = "Request";
$message = "<h1>Request</h1>";
$message .= "<strong>street</strong>:".$_POST['street'];
$message .= "<strong>store</strong>:".$_POST['store'];
$headers = "From: request#domain.com";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html\r\n";
$sent = mail($to, $subject, $message, $headers);
if( $sent = mail($to, $subject, $message, $headers) ){ echo "SENT"; } else { echo "There
was a problem"; }
?>
There were a few problems with your code.
Your headers $headers .= "MIME-Version: 1.0\r\n"; were malformed and were adding 1.0 etc. to the From: therefore resulting in 1.0 <request#domain.commime-version>
Also, your mail() function was being executed twice, therefore sending 2 emails at the same time.
I fixed your headers including your mail() by removing $sent = mail($to, $subject, $message, $headers); and modifying the if condition.
Assuming this is what you are using for an HTML form which I used to test it with:
<form method="POST" action="mail_handler.php">
<p>
<label>Street:<br>
<input name="street" type="text">
</label>
</p>
<p>
<label>Store:<br>
<input name="store" type="text">
</label>
</p>
<input name="submit" type="submit" value="Submit" />
</form>
mail_handler.php
<?php
$to = "user#domain.com";
$subject = "Request";
$message = "<h1>Request</h1>";
$message .= "<strong>street</strong>:".$_POST['street'];
$message .= "<br>";
$message .= "<strong>store</strong>:".$_POST['store'];
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
$headers .= "From: user#domain.com" . "\r\n" .
"Reply-To: user#domain.com" . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers) ){
echo "SENT"; } else { echo "There was a problem"; }
?>
More information on headers and the mail() functions can be found by visiting the PHP.net Website at the following URL: http://php.net/manual/en/function.mail.php
<textarea rows="4" cols="70" name="filename" id="result" style="background:#B0D2D7;
width:100%;overflow:auto;resize:none"
readonly><?php echo $_POST['filename']; ?></textarea>
Hi all, this is a snippet of code I'm using. What I'm struggling with is how to send
the $_POST results that get displayed on the next page into an email using PHP email.
The results are not displayed in a text box as such on the next page but displayed more like a print_pr into a PHP form.
Any help would be great!
To move data across into another page via POST, the easiest way is to wrap your textarea in a form and add a submit button:
<form action="?" method="post">
<textarea name="filename"></textarea>
<input type="submit" />
</form>
<?php
if(isset($_POST["filename"]))
{
echo $_POST["filename"];
}
?>
You also made a vague reference to sending an email, which can be done using the mail() function.
<?
$g_mail = "mail#domain.com";
$s_name = "Some name";
$to = "Receiver <receiver#domain.com>";
$subject = "Some subject";
$message= "HTML codes here. Write anything you want including " . $_POST['data'];
$header = "From: $s_name <".$g_mail.">\n";
$header .= "Reply-To: $s_name <".$g_mail.">\n";
$header .= "Return-Path: $s_name <".$g_mail.">\n";
$header .= "Delivered-to: $s_name <".$g_mail.">\n";
$header .= "Date: ".date(r)."\n";
$header .= "Content-Type: text/html; charset=iso-8859-9\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Importance: Normal\n";
$header .= "X-Sender: $s_name <".$g_mail.">\n";
$header .= "X-Priority: 3\n";
$header .= "X-MSMail-Priority: Normal\n";
$header .= "X-Mailer: Microsoft Office Outlook, Build 11.0.5510\n";
$header .= "X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869\n";
mail($to, $subject, $message, $header);
?>
This is the mail script I generally use. It will not be marked as spam on most mail providers aswell.
I have tried to search online for similar problem, but i just couldn't get it work, it's driving me nuts. haiz. your_email just couldnt pass.
The form
echo '<form class=location_submit name="togo" action="" method="post" >';
echo '<input class="user_email" type="text" name="your_email" placeholder="Enter your email here" required size="55"> <br />';
echo '<input class="location_submit_button" type="image" name="button" src="images/send_location_button.png" />';
echo '<input type="hidden" name="button_pressed" value="1" />';
echo '</form>';
The mail function
if(isset($_POST['button_pressed']))
{
$to = $your_email;
$subject = "Sent from Utourpia!";
$message = "Message body";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: Terence Leong # Utourpia <terence#utourpia.me>" . "\r\n";
$headers .= "Reply-To: terence#utourpia.me" . "\r\n";
$headers .= 'Bcc: terence#popby.me' . "\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();
mail($to, $subject, $message, $headers, '-f terence#utourpia.me');
echo '<p class=email_sent>Email Sent.</p>';
}
Things worth to note is email sent does execute when i click the submit button, but $your_email simply returns NULL :((
you need to extract the values from the $_POST using their names;
$to = $_POST['your_email'];