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
Related
I hosted my website on github.My contact form doesn't work.I used PHP and HTML to make it.Here are my php code lines
PHP:
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$emailFrom = $_POST['email'];
$mobile = $_POST['number'];
$message = $_POST['message'];
$mailTo = "vukstamenkovic9#zohomail.eu";
$headers = "From: ".$emailFrom;
$txt = "You have received an e-mail from ".$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.html?mailsent");
}
?>
When I want to contact,I always get this: 405 Not Allowed
How can I resolve this?I searched it and nothing showed up.I would really appreciate help.
This question already has answers here:
How can I send email with UTF-8 encoding?
(2 answers)
UTF-8 all the way through
(13 answers)
Closed 4 years ago.
I tried several times to implement UTF-8 for receiving mails from my php contact form, but without any luck.
Code looks like this:
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['email'];
$message = $_POST['message'];
$mailTo = "info#mnbl.eu";
$headers = "Od: ".$mailFrom;
$txt = "Dostal jste e-mail od ".$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
if (empty($name) || empty($subject) || empty($mailFrom) || empty($message)) {
header("Location: ../page-contact-form.php?form=empty");
exit();
} else {
if (!filter_var($mailFrom, FILTER_VALIDATE_EMAIL)) {
header("Location: ../page-contact-form.php?form=email");
exit();
} else {
header("Location: ../page-contact-form.php?mailsend");
exit();
}
}
}
?>
I have <meta charset="UTF-8"> in my head, accept-charset="utf-8"in form tag.
Still i recieve mails with weird symbols (input language is Czech).
Do I need anything else?
Thanks in advance.
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;
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!";
}
?>