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
Related
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.
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>
I have a site that contain more than 10000 videos, and sometimes there is embeded video that doesnt work, i need to show to my visitors this message "click here if the video doesnt show anymore" and when they click to this message , i will recieve a notification from the page that has been clicked
I didnt found any joomla extension that can do this
If i put this php code in every page of my joomla website
<form action="" method="post">
<input type="submit" value="Send details to embassy" />
<input type="hidden" name="button_pressed" value="1" />
</form>
<?php
if(isset($_POST['button_pressed']))
{
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
echo 'Email Sent.';
}
?>
It will send me a message in one click.
How can i receive a mail containing the name of page where the user has clicked?
In Joomla with this html code we can obtain the name of the current page.
<? $doc =& JFactory::getDocument();
echo $doc->getTitle();?>
Something like
$message = 'Page:' . $doc->getTitle();
should do the trick.
I have a contact form made with php on my website. The problem is that it perfectly sends english letters but doesn't support russian letters. So, I need to change the encoding, how do i do that?
Here is a code:
<div id="center">
<p class="please">Please contact us using this form.</p>
<div id="formbox">
<?
if (isset ($_POST['message'])) {
$name = # trim ($_POST['name']);
$contact = # trim ($_POST['contact']);
$message = # trim ($_POST['message']);
if (! $name or ! $contact or ! $message) echo ('<p style="color: red">You should fill in all the blanks.</p>');
else { mail ("support#myemail.com",
"Message from Giftosite (Sender: $name)",
"$message \n\n Reply to: \n $contact");
echo ('<p style="color: green">Message has been sent, thank you!</p>');
$_POST['name'] = $_POST['contact'] = $_POST['message'] = '';
}
}
?>
<form method="POST" class="form">
<p class="formcontent">Your name:</p>
<input name="name" value="<?=#$_POST['name'];?>">
<p class="formcontent">Your e-mail address:</p>
<input name="contact" value="<?=#$_POST['contact'];?>">
<p class="formcontent">Message:</p>
<textarea name="message" rows="6" cols="36"><?=#$_POST['message'];?></textarea>
<p><input type="submit" value=" Send "></p>
</form>
</div>
</div>
Set headers in your email
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Content-type: text/html; charset=UTF-8;' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
So, in your code instead of this
mail ("support#myemail.com", $message from Giftosite (Sender: $name)", "$message \n\n Reply to: \n $contact");
You will have
$headers = 'From: webmaster#example.com' . "\r\n" .
'Content-type: text/html; charset=UTF-8;' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail ("support#myemail.com", $message from Giftosite (Sender: $name)", "$message \n\n Reply to: \n $contact", $headers);
You need to set header for your email before sending Unicode characters, try this
$header_ = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n";
mail ("support#myemail.com",
"Message from Giftosite (Sender: $name)",
"$message \n\n Reply to: \n $contact", $header_);