Extra slash on email subject - php

I use this sample of code to send email from php
<?php
$to = 'nobody#example.com';
$subject = $_POST['subject']; //"the \test subject's";
$message = $_POST['body']; //'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
but when i recieve the email the subject displayed like that
the \\test subject's
How to remove this extra slash ?
Thanks

From http://php.net/manual/en/function.mail.php :
subject
Subject of the email to be sent.
Caution Subject must satisfy ยป RFC 2047.
RFC 2047 : http://www.faqs.org/rfcs/rfc2047.html
Wish it will help you.

Related

php: Can't send email

I've made a website with a mailing form, and the php to send it is as follows:
<?php
$to = "example#outlook.com";
$subject = $_POST["subject"];
$message = $_POST["message"];
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
It won't send anything.
Can anyone tell what's wrong in the script?
If it helps on anything, I'm trying to send to an Outlook email.
Thanks

How do I change the sender name of a PHP email?

I have a script that sends an email, but instead of the sender name being "admin#foo.bar", I want it to say "Foobar Admin". How can I do this?
Thanks!
Do you want something like this??
$email_from = $full_name.'<'.$email_from.'>';
try this
<?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);
?>
for reference use http://www.php.net/manual/en/function.mail.php
Use this;
<?php
$to = 'to#mail.com';
$subject = 'Your subject';
$message = 'Your message';
$headers = 'From: Foobar Admin<admin#foo.bar>' . "\r\n" .
'Reply-To: admin#foo.bar' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
mail("recipient#aol.com","subject","message","From:Foobar Admin<foobar#admin.com>");

Sending Email in PHP from a button

Let me start by saying I do not have a lot of programming knowledge. I use a program called PHPRunner to generate most of the php that I do. It is mainly for small office stuff nothing fancy.
My question is:
I have a table that has 6 fields one of them called email. When I go into a record I wanted to put a button called "send notification" that would email the record details to the email address associated with that record.
Any help would be greatly appreciated. I know it is probably out here on the web, possibly searching the wrong way.
You can use the mail function in php. Example from the provided link:
<?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);
?>
For sending email using PHP, use mail() function
http://php.net/manual/en/function.mail.php
Example:
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$from = 'webmaster#example.com';
$headers = 'From: '.$from . "\r\n" .
'Reply-To: '.$from . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>

Send mails with PHP change From Address?

When I send a message with PHP the recipients gets a from address such as this one:
user123#p3nlhg147.shr.prod.phx3.secureserver.net
How can I use my custom email address like info#mydomain.com as sender address?
Part of the mail function is the ability to include headers.
You should send a From header, like so:
$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);
source: http://php.net/manual/en/function.mail.php
If you mean how to change the field From, use this snippet from the official doc:
<?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);
?>

how to send email where "from" having 'firstname'<space>'lastname'<email_id> in php

i have to send email where email "from" having 'firstname''lastname'.
For ex: first_name="john"
last_name="Dime"
email_id="john#john.com"
then from should be like this in the sent mail: From: john dime.
Please help me if u find any solution.
As per RFC 2822, you simply need to set a header of the form...
From: John Dime <john#john.com>
...in the headers portion of your email.
I have found instances of mail not being delivered correctly if the from address is not specified using the -f option with sendmail:
<?php mail($email, $subject, $body, $headers, "-f $email") ?>
Yes simply write your name in "FROM" portion like given below
$headers = 'From: Fname Lname<webmaster#example.com>' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
This is taken from php.net website:
<?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);
?>
You can specify the from field in the additional headers.
You just need to change the webmaster#example.com with the desired string
http://php.net/manual/en/function.mail.php - this can be useful for you

Categories