php Contact Form Coding Issues [duplicate] - php

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I'm trying to create php code for an existing html form. When I try to create the code, it seems to have a problem with the closing parentheses, can anyone help?
<?php
if (isset($_POST['your_name'])) {
$your_name = $_POST['your_name'];
if (isset($_POST['your_email'])) {
$your_email = $_POST['your_email'];
if (isset($_POST['subject'])) ;
$subject = $_POST['subject'];
if (isset($_POST['message'])) ;
$message = $_POST['message'];
$to = "email.co.uk";
$subject = "New Message";
mail ($to, $subject, $message, "From: " . $your_name);
echo "Your message has been sent";
?>
Thanks

This is because you are using ; in every if statement instead of if { .. } statements try this code
<?php
if (isset($_POST['your_name'])) {
$your_name = $_POST['your_name'];
}
if (isset($_POST['your_email'])) {
$your_email = $_POST['your_email'];
}
if (isset($_POST['subject'])) {
$subject = $_POST['subject'];
}
if (isset($_POST['message'])) {
$message = $_POST['message'];
}
$to = "email.co.uk";
$subject = "New Message";
mail ($to, $subject, $message, "From: " . $your_name);
echo "Your message has been sent";
?>

Related

How can I validate email in this PHP contact form? [duplicate]

This question already has answers here:
How to validate an email address in PHP
(15 answers)
Closed 3 years ago.
is there a way to validate an email in this form without rewriting it completely? It'd be great if I could just add something to this. I'm new to PHP and this form is taken from mmtuts video. If you know how to help, I'd be glad if you did.
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$number = $_POST['number'];
$subject = $_POST['subject'];
$mailFrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = "misavoz#seznam.cz";
$headers = "From: ".$mailFrom;
$txt = "Pan/í ".$name." vám poslal/a zprávu. Telefonní číslo: ".$number."\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.php?mailsend");
}
In the past I have used:
if(filter_var($email, FILTER_VALIDATE_EMAIL))
{
//send email
}
else
{
//show error
}
Source: https://www.php.net/manual/en/function.filter-var.php

PHP mail generator - wrong message structure [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 4 years ago.
I have a problem with php mail generator. I don`t understand my code put $visitor_email in message... Can you help me?
id = $_POST['ID'];
$tt = $_POST['TT'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
//Validate first
if(empty($id)||empty($tt)||empty($visitor_email))
{
echo "ID, TT and email are required!";
exit;
}
if(IsInjected($visitor_email))
{
echo "Wrong email!";
exit;
}
$email_from = 'xxx#mymail.com';//<== update the email address
$email_subject = "Something in title";
$email_body = "$message".
$to = "$visitor_email";//<== update the email address
$headers = "From: $email_from \r\n";
//Send the email!
mail($to, $email_subject, $email_body, $headers);
//done. redirect to thank-you page.
header('Location: end-page.html');
Replace . after the $message with ;
. will concatenate the variables.
$email_body = $message;

my code doesn't work (php) [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
my code save info in database but doesn't send the message to email and the alert message not work.
can you help me , please ?
`
if(isset($_POST['send'])){
$to = "nada_26_#hotmail.com"; // this is your Email address
$subject = "Form contact";
$subject2 = "Copy of your form submission";
$name = $_POST['name'];
$from = $_POST['email'];
$subject3 = $_POST['subject'];
$company = $_POST['company'];
$content = $_POST['message'];
$message = "Name: ".$name ." Subject: " . $subject3 . " Company: " . $company ."\n\n".$content;
$message2 = "Here is a copy of your message " . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers); //send the message to the admin
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
$sql ="INSERT INTO threadnn_arab.contactus VALUES('$name','$from','$subject3','$company','$message','')";
$result=mysql_query($sql);
echo "<script> alert('Mail Sent, Thank you, we will contact you shortly.'); </script>";
header('Location: index.php?#contact');
}
?> `
i think it on your email provider, smtp may be.or you can using PHPMailer look like in this question Send email from Hotmail using php

mail sending in php on live server still not sent mail [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
Mail sending in php on live server has still not sent mail.
if(isset($_POST['submit'])) {
/*$to = "rahulravalinfo#gmail.com";
$subject = "".$_POST['name']." New Inquiry About
".$_POST['subject'].""; $message = "Contact No.
".$_POST['contact']." Message ".$_POST['message']." Email
".$_POST['message'].""; $header = "From:rahulravalinfo#gmail.com
\r\n"; $retval = mail ($to,$subject,$message,$header); */
$to = "rahulravalinfo#gmail.com"; // this is your Email address
$from = $_POST['name']; // this is the sender's Email address
$first_name = $_POST['name'];
$subject = "New Inquiry from". $_POST['name'];
$message = "Contact ".$_POST['contact'] . $first_name . " wrote the following:" . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to; $retval = mail($to,$subject,$message,$headers);
if( $retval == true ) {
$i=1; } else {
$i=2; } }
Please ask your server hosting company for the php mail is enable for your selected plan or not.
You can check it using php
if ( function_exists( 'mail' ) )
{
echo 'mail() is available';
}
else
{
echo 'mail() has been disabled';
}

PHP 'email sent' but not received

Stuck on a simple php mail thing. Can anybody spot where I've gone wrong. Would be happy for any help.
<?php
$to = "example#website.co.uk";
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
mail($name, $email, $subject, $message);
if(mail($name, $email, $subject, $message)) {
echo "E-Mail Sent";
} else {
echo "There was a problem";
}
?>
The first comment pretty much said it all, if you need a beginner-friendly tutorial of the mail() function, you should check out PHP Sending E-mails
<?php
$to = "example#website.co.uk";
$name = 'From:'.$_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
if(mail($to, $subject, $message, $name)) {
echo "E-Mail Sent";
} else {
echo "There was a problem";
}
?>
Try this instead, it would need spam proofing etc...
<?php
$to = 'example#example.com';
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = 'From: contact#yoursite.com';
mail($to, $subject, $message, $headers);
?>

Categories