Php contact form Encoding issue - php

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_);

Related

Send HTML in email via PHP with datepicker values

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

How to create contact form and mail to the owner of website [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I want to get customers details through contact form and that would be sent to my mail id. so I am trying to code but its not working. I have tried by watching YouTube videos
This is my HTML Code
<!DOCTYPE html>
<html>
<head>
<title>Form</title>
</head>
<body>
<form action="send.php" method="POST">
Name: <input type="text" name="name" required=""></input><br><br>
Mobile: <input type="text" required="" name="mobile"></input><br><br>
Message: <textarea rows="10" cols="50" name="mes" required=""></textarea><br><br>
<input type="submit" value="Send Mail"></input>
</form>
</body>
</html>
This is my PHP Code
<?php
$name =$_POST['name'];
$mobile =$_POST['mobile'];
$mes =$_POST['mes'];
mail("imjeevajk#gmail.com","Contact From Site",$mes,"From: $name\r\n","Mobile: $mobile\r\n");
echo "Thanks for Contacting Us";
?>
mail function as described here http://php.net/manual/en/function.mail.php
Example:
<?php
$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);
?>
So the header "From" must be an email address while you are putting a custom name.
How to get mail function delivery mail to 'to' address please read here
It is mostly correct.
You can't pass Mobile as the additional parameter, that will do nothing.
I have changed the script to append the mobile to the message body.
To set a from address, you need to have a from email, just a name by itself won't work.
Also depending on your php configuration and mail server configuration, you may not be able to change the from address and it will result in an error, or be ignored.
<?php
if ($_POST) {
$name = $_POST['name'];
$mobile = $_POST['mobile'];
$mes = $_POST['mes'];
// append mobile to message
$mes .= "\r\nMobile: $mobile\r\n";
$from_email = "imjeevajk#gmail.com';
mail("imjeevajk#gmail.com", "Contact From Site", $mes, "From: $name <$from_email>\r\n");
// mail("imjeevajk#gmail.com", "Contact From Site", $mes, "From: $name\r\n", "Mobile: $mobile\r\n");
echo "Thanks for Contacting Us";
exit;
}
Please set submit name field and update the php mail function as mentioned below.
<input type="submit" name="sendMail" value="Send Mail"></input>
<?php
if (isset($_POST['sendMail'])) {
$to = 'admin#dummyemail.com';
$subject = 'Contact From Site';
$from = "From: ".$_POST["name"]."\r\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
$message = '<html><body>';
$message = "Name: ".$_POST["name"]."";
$message .= "Mobile: ".$_POST["mobile"]."";
$message .= "Message: ".nl2br($_POST["mes"])."";
$message .= '</body></html>';
if(mail($to, $subject, $message, $headers)){
echo 'Thanks for Contacting Us.';
} else{
echo 'Unable to send email. Please try again.';
}
}
?>
Better use PHP Mailer
some servers providers block mail function and that can be reason why it doesn't work.

how to send email message with php and html

I am trying to send a message from HTML form. But for some reason I am not getting anything. Could someone please help me ?
Here is my HTML form:
<form method="post" action="subb.php">
<div class="field half first">
<label for="Name">Name</label>
<input type="text" name="Name" id="name" />
</div>
<div class="field half">
<label for="Email">Email</label>
<input type="text" name="Email" id="email" />
</div>
<div class="field">
<label for="Message">Message</label>
<textarea name="Message" id="message" rows="5"></textarea>
</div>
<ul class="actions">
<button type "submit" name="submit" id="submit" class="button submit">Send message</button>
and the PHP:
<?php
$Name = $_POST['Name'];
$Email = $_POST['Email'];
$Message = $_POST['Message'];
$to = "combatstriker111#gmail.com";
$subject="new message";
mail($to , $subject , $Message, "From :" . $Name . $Email);
echo "Your message has been Sent";
?>
I have named the PHP file subb.php and listed them both in the same directories but its still not working for some reason. Any help is very much appreciated.
Something in your code was wrong mail($to , $subject , $Message, "From :" . $Name . $Email);
Mail function SYNTAX :
mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
So,
<?php
if(isset($_POST['submit'])) {
$Name = $_POST['Name'];
$Email = $_POST['Email'];
$Message = "Name : ".$Name."<br />"
$Message .= $_POST['Message'];
$to = "combatstriker111#gmail.com";
$subject="new message";
// 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";
// Additional headers
$headers .= 'To: Name <$to>' . "\r\n";
$headers .= 'From: $Name <$Email>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
if(mail($to, $subject, $Message, $headers)) {
echo "Your message has been Sent";
} else {
echo "Mesage Error";
}
}
?>
Note : Use any mail library for prevent vulnerable to header injection like PHPMailer
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];;
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = 'info#fullertoncomputerepairwebdesign.com';
$subject = 'Message From Website';
$headers = 'From: info#fullertoncomputerepairwebdesign.com' . "\r\n" .
'Reply-To: info#fullertoncomputerepairwebdesign.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$themessage = "Name: ".$name."</br>Email: ".$email."</br>Phone: ".
$phone."</br>Subject: ".$subject.
"</br>Message: ".$message;
//echo $themessage;
if(mail($to, $subject, $themessage, $headers)){
echo "message sent";
header( 'Location: http://www.fullertoncomputerepairwebdesign.com/contactus.php?smresponse=Message Sent' ) ;
}else{
echo "we have a error charlie!";
}
;
test this out and if it doesn't work it means your hosting blocks mail function.

FORM: Name as sender instead of e-mail.

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.

PHP email function not working [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I have the following php code on my HTML page:
<body>
<?php
if ($_POST) {
$message = 'Name :' . $_POST['name'] . "\n" .
'Email :' . $_POST['email'] . "\n" .
'Phone :' . $_POST['phone'] . "\n" .
'Date :' . $_POST['book'] . "\n" .
'Message :' . $_POST['message'];
mail('ruan#gmail.com', 'Contact-us Form', $message);
}
?>
And HTML as the following:
<form method="post" action="contact.php" onsubmit="return valid()" enctype="multipart/form-data">
<ul>
<li>
<p class="left">
<p>Name</p>
<input type="text" name="name" placeholder="John Doe" />
</p>
.....
</form>
Now i have changed the email address to check if that could be the problem but still, I don't receive any email.
I think you need to include headers for php mail function
<?php
$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);
?>
check out this link http://php.net/manual/en/function.mail.php.
If still not working check your smtp setting for your server. If also not working then use phpmailer. Check out this link for phpmailer http://phpmailer.worxware.com/?pg=examples

Categories