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).
Related
I'm trying to use the following code to try and send a PHP Email with a PDF attachment.
I get the message 'Mail Sent. Thank You'. However, No email is being sent.
Please could someone show me / explain to me where I am going wrong?
Thanks
<?php
if(isset($_POST['submit'])){
$to = "example#example.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$subject = "Subject Here";
$message = $_POST['message'];
$file = $_POST['upload'];
$headers = 'From: someone#gmail.com ' . "\r\n" .
'Reply-To: someone#gmail.com ' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers2 = "From:" . $to;
mail($to, $subject, $message, $file, $email, $headers);
echo "Mail Sent. Thank you.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>
<!DOCTYPE html>
<head>
<title>Form submission</title>
</head>
<body>
<form action="" method="post">
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="file" name="upload" accept="application/pdf,application/vnd.ms-excel" />
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
There are lot of issues with your code, and it is recommended to first check the syntax and documentation on official site. For instance your are passing $file as parameter to mail function, but there is no FILE parameter in mail function (https://www.php.net/manual/en/function.mail.php)
Then you are not saving the uploaded PDF to any disk to send from. Uploaded files are captured through $_FILES variable not $_POST variable. You need to see that too.
Then sending any file is tricky job, and your job can be ease by using some library function such as PHPMailer so try to refer those.
I've written an simple PHP mail form but it refuses to run on one server but will on another. Both servers are running PHP 5.4 and other PHP progs run on the problematic server but mail will not send.
I've pared the mailer back to the simplest code but am stumped as why one server wont send the mail. Is there a configuration I need to activate or a test I can perform to diagnose the problem?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Simple PHP Mailer</title>
</head>
<body>
<form action="" method="post">
First Name: <input type="text" name="first_name"><br>
Last Name: <input type="text" name="last_name"><br>
Email: <input type="text" name="sender_email"><br>
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="submit" name="subdata" value="Submit">
</form>
<?php
//Taken from: http://stackoverflow.com/questions/18379238/send-email-with-php-from-html-form-on-submit-with-the-same-script
if(isset($_POST['subdata'])){
$to = 'myname#gmail.com'; // this is your Email address
$from = $_POST['sender_email']; // this is the sender's Email address
$fname = $_POST['first_name'];
$lname = $_POST['last_name'];
$subject = "PHP Email Form Test";
$message = $fname . ' ' . $lname . ' (' . $from . ') wrote the following:' . '\n\n' . $_POST['message'];
$headers = 'From: user#gmail.com' . "\r\n" .
'Reply-To: user#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if (mail($to, $subject, $message, $headers)) {
echo 'Mail Sent. Thank you ' . $fname . ', we will contact you shortly.';
}else{
echo 'Mail Error';
}
}
?>
</body>
</html>
Any help would be appreciated, many thanks.
Kw
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.