I have some problem here, I don't see the mistake, it was sending mail before I started using the POST var, but after I set them, mail is not sending, but I still see the screenOK.
$full_name=$_POST["full_name"];
$to = 'admin#mail.com';
$subject = 'Call me';
$message = "call $full_name";
$headers = 'From: admin#mail.com' . "\r\n" .
'Reply-To: '. "\r\n" .
'X-Mailer: PHP/' . phpversion();
if( mail($to, $subject, $message, $headers)){
echo '<script>
$("submit").click(screenOk);
</script>';
}
else echo 'STH got wrong';
?>
the form is here:
<form action=notify.php method=POST>
<div class=field>
<label for=full_name class=full-name>
<svg ...>...</svg>
</label>
<input name=subscriber[full_name] id=full_name placeholder="Your name" class="js-page text-field" data-page=/NameField></div>
What I did wrong?
Your form input is named subscriber[full_name] but you're trying to access it using
$_POST['full_name']
Try changing these to match;
for instance;
<input name="full_name" >
Some reading material: http://www.php.net/manual/en/language.variables.external.php
Try it
you POST variable not matching
<input name="full_name" id="full_name" placeholder="Your name" class="js-page text-field" data-page=/NameField>
Related
I want to have a page with some form inputs and with date picker i want to send these all fields to mail how to i do this with PHP?
You can do that by first getting what users typed in a form.
Then parse the input into a text file or html file that you can send using the mail() function in PHP.
for example for a "datepickerfield" field:
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = $_GET['datepickerfield'];
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
You can access the form input fields in PHP over $_GET or $_POST. This depends on your form.
<form action="/mail.php" method="get">
or
<form action="/mail.php" method="post">
Here's an example:
HTML Form:
<form action="/mail.php" method="post">
<label for="fullname">Full name:</label>
<input type="text" id="fullname" name="fullname">
<label for="birthday">Birthday:</label>
<input type="date" id="birthday" name="birthday">
<input type="submit" value="Submit">
</form>
and in your php file :
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$message = 'The Birthday of '.$_POST['fullname'].' is: '.$_POST['birthday'];
mail($to, $subject, $message, $headers);
?>
Take a look at https://www.php.net/manual/en/function.mail.php
i'm trying to get a message to appear after my form has been submitted, i can get the form to submit and the page to then refresh but unsure how to add the message after the refresh.
i have no knowledge of PHP so sorry is its and obvious answer
thanks
my html & PHP if needed
<form action="action.php" method="POST" target="my_iframe" onsubmit="setTimeout(function(){window.location.reload();},10);">
<input type="text" id="name" name="name" placeholder="name" required="required">
<input type="email" id="email" name="email" placeholder="email" required="required">
<input type="tel" id="phone" name="phone" placeholder="phone">
<div class="form-row" style="display:none;"><input type="hidden" name="url" placeholder="URL"></div>
<textarea id="message" name="message" placeholder="message" style="height:200px" required="required"></textarea>
<input id="submit" type="submit" value="submit">
</form>
<iframe name="my_iframe" width="1" height="1" style="border:none"></iframe>
<?php
$to = 'zoeharrisondesign#gmail.com';
$subject = 'New Message Recieved!';
$from = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$name = $_POST['name'];
//check honeypot
if( !empty( $honeypot ) ) {
echo 'There was a problem';
}
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Create email headers
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
// Compose a simple HTML email message
$message = "$message \r\n |
From $name \r\n |
Tel: $phone";
// Sending email
if(mail($to, $subject, $message, $headers)){
echo 'Your message has been sent successfully.';
} else{
echo 'Unable to send email. Please try again.';
}
?>
Update your php sending email to this
if (mail($myEmail, $subject, $message)){
$success = "Message sent successful";
}else{
$success = "Message Sending Failed.";
}
Then add this php codes in your html codes add this code to display a message. Put it on top of your form html tag.
<?php
if (isset($success)){ echo "<div>" . $success . "</div>";}
?>
You may even add some styling on the message if you prefer.
I have a contact form which sends emails but displays my email server as the "from" and hence it is difficult to reply to emails sent from the contact form
I have tried adding
$headers = 'Reply-To: ' . $email . "\r\n" . 'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
to my script but although this works perfectly in respect to sending an email you can reply to, it still also sends an email which you cannot reply to!
I am a PHP newbie so I think I have made an error making two messages send, if someone could please point out what it is that would be much appreciated as although I have looked at other similar questions on here I cannot find a solution
Here is my code:
include ("includes/header.php");
$pagetitle = "Contact Us";
$description = "";
$keywords = "";
$name = ($_POST['name']);
$email = ($_POST['email']);
$message = ($_POST['message']);
$from = ($_POST['email']);
$to = 'info#mydomain.co.uk';
$subject = "Enquiry from Visitor " . $name;
$human = ($_POST['human']);
$headers = 'Reply-To: ' . $email . "\r\n" . 'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
<div class="container-fluid contactform">
<div class="col-md-6 contactform-padding">
<h2>Contact Us</h2>
<?php
if (isset($_POST['submit']) && $human == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Thanks for getting in touch. Your message has been sent & We will get back to you shortly!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if (isset($_POST['submit']) && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
?>
<form method="post" action="index.php" data-ajax="false" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label class="control-label " for="name">
<p>Name</p>
</label>
<input class="form-control" id="name" name="name" type="text"/>
</div>
Please could someone point out to me why this is sending two emails? I would REALLY appreciate it - I know I have made a stupid mistake and I cannot see why/how
Thanks!
Please check code once again.
You are calling mail function two times.
One in above and another in if condition
from above code remove the mail function
mail can be sent from your if condition
I have mail.php which sends out an email. This is the code I'm using.
<?php
if(isset($_POST['submit'])){
$to = $_POST['email'];
$subject = 'Your Results!';
$message = $_POST['message'];
$headers = 'From: example#example.com' . "\r\n" .
'Reply-To: example#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
//mail($to, $subject, $message, $headers);
//header("Location: thankyou.php");
echo $message;
}
?>
The contents of the email is supposed to the .innerText of of a div I have on my index.php page. If I echo out the message, then the output appears the page (mail.php) but when I comment/uncomment the necessary parts to email myself the message I receive is just "undefined".
Is $message not defined?
Here is the form and javascript I'm using
<form action="mail.php" method="post" onsubmit="this.message.value = document.getElementById('box').innerText;">
<input type="email" name="email" required>
<input id="content" type="hidden" name="message" value="">
<input type="submit" name="submit">
</form>
Change .innerText to .textContent. .innerText is a nonstandard property that doesn't exist in Firefox.
I don't know why you didn't have the same problem when used echo $message in the PHP script, unless you tested that version of the script with a different browser (always try to minimize the number of differences when you're testing like this).
I have a very basic form that uses PhpMail to send it's content but is there some way to change the "sender name" of the form from an e-mail adress to a name.
Example:
Instead of "from: form.ello#whatever.org" it says "From: Ello Recruitment" or whatever.
Here's the code i'm currently using:
HTML:
<form name="10_percent" action="http://www.whatever.org/recruit.php" method="post" style="text-align:center;">
<label for="description"><p>Description</p></label>
<textarea name="description" id="description" rows="4" cols="50"></textarea>
<input type="submit" id="submit" name="submit" value="Send" style="width:88px; height:24px;"/>
</form>
PHP:
<?php
if(isset($_POST['submit'])) {
$to = "xxx#whatever.org";
$subject = "Recruitment";
$epost_field = $_POST['description'];
$headers = "Content-type: text/html; charset=utf-8\r\n";
$headers = 'From: Ello Recruitment' . "\r\n" .
'Reply-To: xxx#whatever.org' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$body = "$description_field\n";
echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.whatever.org\">";
mail($to, $subject, $body, $headers);
} else {
echo "not working";
}
?>
Marcel was nearly there - you need to change the From header:
$headers = 'From: Ello Recruitment <form.ello#whatever.org>' . "\r\n" .
You may have trouble setting the From address on some servers, for example gmail doesn't let you do this arbitrarily.
I would recommend you use a library to send email from PHP as it will do all this kind for formatting for you correctly.