This question already has answers here:
PHP E-Mail Encoding?
(7 answers)
Closed 5 years ago.
I have this web page.
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Send Email</title>
</head>
<body>
<form method="GET">
<input type="text" name="myEmail" placeholder="Имейл"/><br>
<input type="text" name="recieverEmail" placeholder="Получател"/><br>
<input type="text" name="subject" placeholder="Предмет"/><br>
<textarea rows="4" cols="50" name="message" placeholder="Съобщение"></textarea><br>
<input type="submit" name="button" value="send"/>
</form>
<?php
if(isset($_GET['button'])){
$sender = $_GET['myEmail'];
$reciever = $_GET['recieverEmail'];
$subject = $_GET['subject'];
$message = $_GET['message'];
$headers = "From: " . $sender . "\r\n";
mail($reciever, $subject, $message, $headers);
}
?>
</body>
</html>
I get data from the html form. I need a way to set the encoding of the email to UTF-8 because when I want to send email in Bulgarian, it is not translating into Bulgarian. Any ideas? Thank you in advance.
Add one more header attribute in your code like this:
if(isset($_GET['button'])){
$sender = $_GET['myEmail'];
$reciever = $_GET['recieverEmail'];
$subject = $_GET['subject'];
$message = $_GET['message'];
$headers = "From: " . $sender . "\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8"; //check this header attribute. It will append to the `From` header.
mail($reciever, $subject, $message, $headers, $encoding);
}
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 3 years ago.
I have an HTML form that posts to a PHP mail function. For some reason it does not send the content anymore. The emails display "This email has no content." Am I missing something?
//HTML - Post method form.
<form class="form" id="form" action="submitform.php" method="post">
<h2 style="padding-top: 10px;">Contact Us</h2>
<input class="input" type="text" placeholder="Name" name="name"><br>
<input class="input" type="text" placeholder="E-Mail Address" name="email"><br>
<input class="input" type="text" placeholder="Phone #" name="phone"><br>
<textarea class="input" placeholder="Questions, Specifications, etc."
name="message</textarea>
<input class="inputButton" type="submit">
</form>
//PHP - Gets posted HTML input data and sends it to the email, formatted with \n
<?php
$to = 'example#example.com' ;
$subject = 'Inquiry' ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$phone = $_POST['phone'] ;
$message = $_POST['message'] ;
$message = "From: $name \nEmail: $email \nPhone: $phone \nMessage: $message \n";
$sent = mail ($to, $subject, $message) ;
if($sent == true) {
echo "<h3>Thank you for your inquiry.</h3>";
}else{
echo "<h3>Sorry, your message wasn't sent.</h3>;
}
?>
I've found defining headers, even if I just want default values, helps me get my mail delivered. I can't say this is what you need to do because your code looks like it should run successfully as is.
An example of setting the headers to (I believe) default values:
$to = $to_email;
$subject = $your_subject;
$message = $your_message;
$headers = "From: S.O.<no-reply#dontusethis.email>\r\n" .
"Reply-To: [can be nice, not needed of course]\r\n" .
"X-Mailer: PHP/" . phpversion();
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to,$subject,$message,$headers);
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 3 years ago.
I'm trying to make a contact form in HTML page. I've linked it with a .php file and but both on a server but I don't receive any email. Someone can see my mistake?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Contact form tutorial</title>
</head>
<body>
<main>
<p>SEND EMAIL</p>
<form action="contactform.php" method="post">
<input type="text" name="name" placeholder="Full name">
<input type="text" name="mail" placeholder="Your e-mail">
<input type="text" name="subject" placeholder="subject">
<textarea name="message" placeholder="Message"></textarea>
<button type="submit" name="submit">SEND MAIL</button>
</form>
</main>
</body>
</html>
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = "MINE#EMAIL.COM";
$headers = "From: ".$mailFrom;
$txt = "You have received an e-mail from ".$name.".\n\n" . $message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.php?mailsend"); }
I think the issue is with your headers. I altered your script to conform the headers to the docs and it worked. I also sent a version with no headers and it worked as well.
$name = 'name';
$subject = 'subject';
$mailFrom = 'MINE#EMAIL.COM';
$message = 'message';
$mailTo = 'me#realaddress.com';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$txt = "You have received an e-mail from ".$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 4 years ago.
I want to make a website(small one) I want to make people able to send write their username and password to be sent to my email(because I am still developing a database and I want to make sure if it will work or not)
I tried to put php in the same file as html but when it processes the code it just shows the code but dooesn't run it
<html>
<head>
<?php
if(isset)($_POST['name']) && isset($_POST['email'])) {
$pass = $_POST['pass'];
$email = $_POST['email'];
$to = 'omar12haytham#gmail.com';
$subject = 'Password';
$body = '<html>
<body>
<h2>Hello</h2>
<hr>
<p>Email<br>' . $email . '</p>
<p>Password<br>' . $pass . '</p>
</body>
</html>';
//headers
$headers = "From: ".$name." <".$email.">\r\n";
$headers .= "Reply-To: ".$email."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8";
//send
$send = mail($to, $subject, $body, $headers);
if ($send) {
echo '<br>';
echo 'Your email or password is incorrect';
} else {
echo error;
}
}
</head>
?>
<body>
<form action="" method="post">
<input type="text" name="name" placeholder="Write your email"><br>
<input type="password" name="email" placeholder="Write your password"><br>
<button type="submit">Log in</button>
</form>
</body>
</html>
I expected it to send me an email but it doesn't must I launch it? I am testing it as .html file not as a working website.
This piece of code doesn't work: isset)($_POST['name']) use instead if(isset($_POST["name"]))
For some reason the $name, $email and $message variables aren't being passed into the $msgcontents and $headers variables. After I fill out the form and click submit the message in my inbox looks like this:
Subject: Message from Contact Form
From: Unknown sender
Date: Mon, November 17, 2014 7:44 pm
To: myemail#myemail.com
Name:
Email:
Message:
I've used var_dump() to see if my variables are being populated after clicking submit and they are but for some reason they are not being picked up by $msgcontents and $headers. Where am I going wrong?
Here's my code:
<?php
$name = trim(htmlspecialchars($_POST['name'], ENT_QUOTES));
$email = trim($_POST['email']);
$message = trim(htmlspecialchars($_POST['message'], ENT_QUOTES));
$to = "myemail#myemail.com";
$subject = "Message From Contact Form";
$msgcontents = "Name: $name <br> Email: $email <br> Message: $message";
$headers = array("MIME-VERSION: 1.0",
"Content-type: text/html; charset=iso-8859-1",
"From: $name <$email>",
"Reply-To: contact#info84.com",
"X-Mailer: PHP/" . PHP_VERSION
);
$headers = implode("\r\n", $headers);
$mailsent = mail($to, $subject, $msgcontents, $headers);
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form id="contactform" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" novalidate>
<input type="text" name="name" placeholder="Your Name">
<input type="email" name="email" placeholder="Your Email">
<textarea name="message" placeholder="Your Message"></textarea>
<input type="submit" name="submitform" value="send">
</form>
<?php
var_dump($to);
?>
<br>
<?php
var_dump($subject);
?>
<br>
<?php
var_dump($msgcontents);
?>
<br>
<?php
var_dump($headers);
?>
<br>
<?php
var_dump($name);
?>
<br>
<?php
var_dump($email);
?>
<br>
<?php
var_dump($message);
?>
</body>
</html>
I think you check the message sended from first page load (without the form)
Try to wrap your email sending code, like this:
if (isset($_POST['submitform'])) {
//...
mail(...);
//...
}
Then, when page loads no message been sended, but when you click a submit button, mail been sended
This question already has answers here:
Failed to send HTML mails using PHP mail()
(3 answers)
Closed 8 years ago.
I'm trying to send e-mails with html content.
I want to insert some images on it, but i dont know how can i do that, here my code:
<?php
if(isset($_POST['submit'])){
$to = $_POST['to'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = 'From: myemail#gmail.com' . "\r\n" .
'Reply-To: '.$to.' ' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
?>
<form method="POST">
<input type="text" placeholder="from" name="from" />
<input type="text" placeholder="to" name="to" />
<input type="text" placeholder="Subject" name="subject" />
<textarea type="text" placeholder="Message" name="message"></textarea>
<input name="submit" type="submit" />
</form>
Thanks guys
Just need to pass the appropriate headers to the mail function:
// Send HTML Message
$headers = 'MIME-Version: 1.0' . PHP_EOL;
$headers .= 'Content-type: text/html; charset=iso-8859-1' . PHP_EOL;
$headers .= 'From: example name <example#example.com>' . PHP_EOL;
mail('to#example.com', 'Subject', $output, $headers);
$to = "$email";
// Change this to your site admin email
$from = "admin#MYSITE.COM";
$subject = "Welcome to MYSITE.COM";
//Begin HTML Email Message where you need to change the activation URL inside
$message = '<html>
<body bgcolor="#FFFFFF">
Dear ' . $firstname . ',
<br /><br />
Thank you for joining MYSITE.COM.
<br /><br />
You can now start shopping on our website and enjoy all of our services.
Please click on the link bellow to go to our website >>
http://www.MYSITE.COM
<br /><br />
Your Login Details is as follows:
<br /><br />
E-mail Address: ' . $email . ' <br />
Password: ' . $password . '
<br /><br />
Regards
MYSITE.COM
</body>
</html>';
// end of message
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
$to = "$to";
// Finally send the activation email to the member
mail($to, $subject, $message, $headers);
You can edit the code to suit your needs. but it should help you understand how to send an HTML eMAIL directly from PHP.