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;
Related
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
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";
?>
This question already has answers here:
How can I send an email using PHP?
(20 answers)
Closed 5 years ago.
I wanted to send an email such as an confirmation email to an email address that the user has alredy specified in an input tag. Exampe:
I type in my email in an input tag and then I would recive an email at the address I entered in the input tag. Thanks, and If you know the answer could you possibly send me an code to paste in. (Im an php noob)
<?php
$recipient = $_POST['email']; //recipient
$email = "your#domain.com"; //senders e-mail adress
if((filter_var($email, FILTER_VALIDATE_EMAIL)) && ($robotest == "")) {
$Name = ($_POST['name']); //senders name
$mail_body = !!!----> WHAT DO I PUT HERE <----!!!!
$subject = "Porter Inquiry"; //subject
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields
mail($recipient, $subject, $mail_body, $header); //mail command :)
} else {
print "You've entered an invalid email address!";
}
?>
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I am having trouble with sending emails through PHP.
So I have a form which submits to a PHP script which sends an email:
<?php
$to = "myemail#email.com";
$subject = "[Contact Form]";
$name = $_POST["name"];
$contactNumber = $_POST["contactNumber"];
$email = $_POST["email"] ;
$message = $_POST["message"];
$body = "Someone has sent a new message from the contact form. \n \n Message from: " . $name . "\n Contact Number: ". $contactNumber ."\n Email: ". $email ."\n \n Message: ". $message;
if (mail($to, $subject, $body)) {
echo ("<p>Email successfully sent!</p>");
} else {
echo ("<p>Email delivery failed…</p>");
}
?>
And the email is sent fine when for example the message is one line such as:
"Hi there how is it going?"
And fine if it is multiple lines such as
"Hi there
how is it going?"
But when I try and type a message with a comma such as
Hello there,
how is it going?
It fails?
Is there a way I can just treat the whole thing as a string possibly? Would this also fail on any other characters or is this issue just because of the way I am writing the PHP script?
This might be an obvious fix but I am new to PHP so apologies! I have tried looking around for an answer but nothing seems to fix what I am looking for.
Thanks for any help!
Try using headers in your mail function, like this:
$headers = 'MIME-Version: 1.0\r\n';
$headers .= 'Content-type: text/html; charset=UTF-8\r\n';
mail($to, $subject, $body, $headers)
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I'm trying to learn a bit of basics of PHP, but as always I start from living examples like mailing. I'm not sure my tutorial was prepared good or I just made a couple of silly mistakes. There may be a problem with " ' because I haven't figured out which one should be where :) So, my mail is not sending an email, and definitely it's not going to spam so I believe I screw up ' and " part. Thanks for help!
$name = $_POST['nick'];
$visitor_email = $_POST['email'];
$visitor_tel = $_POST['tel'];
$message = $_POST['msg'];
$email_from = 'mail#mail.pl';
$email_subject = "Nowe zlecenie: ";
$email_body = "Nowe zlecenie od $name.\n".
"Email kontaktowy: $visitor_email".
"Telefon kontaktowy: $visitor_tel".
"Zlecenie: $message".
$to = 'mail#mail.pl';
$headers = "Od: $email_from \r\n";
mail($to,$email_subject,$email_body,$headers);
For debugging do like below:
if(mail($to,$email_subject,$email_body,$headers))
echo "mail sent";
else
echo "not send";