PHP mail() from not working [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am using mail() on my site, and the function is working, but the from address is not showing my email address, it is showing name#mailchannels.net
$ito_email = "$inameuser";
$ifrom_email = "info#mywebsite.co.za";
$isubject = "My subject";
$icomment = "Hello $inameuser,\r\n\r\n"
. " \r\n"
. "Subject: $isubjectnote"
. " \r\n"
. "Notice: $inote"
. " \r\n"
. "\r\n"
. "Many thanks";
//send email
mail($ito_email, "$isubject", $icomment, "From: Support " . $ifrom_email);

Changing
mail($ito_email, "$isubject", $icomment, "From: Support " . $ifrom_email);
to
mail($ito_email, "$isubject", $icomment, "From: Support <" . $ifrom_email . ">");
Should allow you to include a readable name as well as the FROM e-mail address.

EXAMPLE:
$email = "emailfrom#anything.com";
$headers = 'From: ' . $email . '' . "\r\n" . "Content-type: text/html;charset = windows-1250";
$subject = $email . ' - New message';
mail("your email", $subject, "email message", $headers);

$to = 'abc#xyz.com'; $subject = 'the subject';
$message = 'Message';
$headers = 'From: xyz#xyz.com' . "\r\n" .'Reply-To: xyz1#xyz.com' . "\r\n";
mail($to, $subject, $message, $headers);
OR
$headers .= $headers; Concat

Related

How can I style PHP code using HTML tags? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am triggering an email to be sent with data from a filled out form once a submit button has been clicked. The email successfully sends with the correct data, however, I am wanting to be able to apply some basic styling to the email such as some <h3> or <strong> tags. Am I able to do this within my php $message variable, and if so, what would that look like?
<?php
$to = "test#test.com"; // this is your Email address
$from = "test#test.com"; // this is the sender's Email address
$company_name = $_POST['company_name'];
$rep_name = $_POST['rep_name'];
$prod_type = $_POST['prod_type'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$subject = "New Form Submission";
$message = "New Form Submission" . "\n" . "\n" .
"Company Name: " . $company_name . "\n" .
"Representative Name: " . $rep_name . "\n" .
"Product Type: " . $prod_type . "\n" .
"Address: " . $address . "\n" .
"City: " . $city . "\n" .
"State: " . $state . "\n" .
"Zip: " . $zip . "\n" .
"Phone: " . $phone . "\n" .
"Email: " . $email . "\n";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
?>
Edit:
I have tried using ob_start() and ob_get_clean() that I found at this link Defining html code inside PHP variables but had no success
Set Content-Type: text/html header to enable HTML emails;
$headers = "From:" . $from;
$headers .= "Content-Type: text/html";
Add some HTML elements to the email;
$message = <<<EOL
<h1>Hi!</h1>
<h2>HTML Emails are awesome!</h2>
EOL;
mail($to, $subject, $message, $headers);
Small working example;
<?php
$to = '----';
$subject = 'SO test Mail';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$message = <<<EOL
<html>
<body>
<h1>Hi!</h1>
<h2>HTML Emails are awesome!</h2>
</body>
</html>
EOL;
if ($res = (mail($to, $subject, $message, $headers))) {
echo 'OK';
} else {
echo 'Error';
var_dump($res);
}

Echoing image in php mail , showing error

I have a form when a user enters data and submits, it will go to his mail, now I am having problem with keeping my logo in the mail, below is my php code for mail
<?php
if(isset($_POST['submit'])){
$to = "contact#bolstersolutions.com"; // this is your Email address
$from = $_POST['name1']; // this is the sender's Email address
$first_name = $_POST['name2'];
$last_name = $_POST['email2'];
$last_name1 = $_POST['number1'];
$subject = "Referal";
$subject2 = "Your Friend " . $from . " Has Referred You To Us For UK Process";
$message = $from . " has refered the following student :" . "\n\n" . $first_name. "\n\n" .$last_name. "\n\n" .$last_name1;
$message2 = "Your friend " . $from . " has referred you to Bolster Solutions for UK process. We will be more than happy to process your applications, thus helping you in achieving your goals to study MS in UK." . "\n\n" . "Feel free to go to the following url for more information or else you can also call us # +91 9666999430 / 7661919191." . "\n\n" . "URL: https://consultancy.bolstersolutions.com/mail/" . "\n\n" . "Thanks and Regards." . "\n\n" . echo "<img src='https://consultancy.bolstersolutions.com/mail/assets/img/logo.png'>" ;
$headers = "From:" . $from;
$headers2 = "From: Bolster Solutions " . $to;
mail($to,$subject,$message,$headers);
mail($last_name,$subject2,$message2,$headers2);
}
?>
the following error is happening:
Parse error: syntax error, unexpected 'echo' (T_ECHO) in C:\xampp\htdocs\mail\index.php
Can anyone please help me with this, thanks in advance.
Remove echo in $message2
Set headers like this
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
Then send : mail($last_name,$subject2,$message2,$headers);
There is a syntax error near: ..."\n\n" . echo "<img src.... Removing echo should solve it.

unable to send multiple bcc mail [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am trying to send Bcc mail .My mail function is working for single mail but when I am trying for bcc mail then I nothing happen .help me for possible solution .
<?php
if(isset($_POST['submit'])){
//$to = "example#com"; // this is your Email address
$to = "example#com";
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['name'];
$last_number = $_POST['number'];
$last_query = $_POST['query'];
$last_state = $_POST['state'];
$subject = "Form submission";
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name ." ".$last_number." ". $last_query." ".$last_state." ". " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo $mag="Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>
You need to send Bcc in headers only like below:
headers .= "Bcc: addess1,addess2,etc \r\n";
you should try this format. also there is no bcc in your code
$headers = 'MIME-Version: 1.0' . "\\r\ ";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\\r\ ";
$headers .= 'To: test <test#example.com>, test1 <test1#example.com>' . "\\r\ ";
$headers .= 'From: test3 <test3#example.com>' . "\\r\ ";
$headers .= 'Cc: [email]test4#example.com[/email]' . "\\r\ ";
$headers .= 'Bcc: [email]test5#example.com,test6#myserver.com,test7#gmail.com,test8#email.com[/email]' . "\\r\ ";
mail($to, $subject, $message, $headers);

can't send mail in php using mail function [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I was trying to send mail by php, the function mail returns 1, but i didn't get
the mail in my inbox
if (isset($_POST["firstName"]) == false)
return;
$to = "mymail#mail.com";
$subject = $_POST["subject"];
$message = $_POST["content"];
$headers = 'From: ' . $_POST["email"] . "\r\n" .
'Reply-To: ' . $_POST["email"] . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$from = "From: " . $_POST["firstName"] . " " . $_POST["lastName"] . " <" . $_POST["email"] . ">";
echo mail($to, $subject, $message, $headers);
echo '<script type="text/javascript">alert("sent message succesfully");</script>';
Using PHP's mail() function it's possible. Remember mail function will not work in Local server.
<?php
$to = 'abc#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: admin#example.com' . "\r\n" .
"CC: somebodyelse#example.com";
mail($to, $subject, $message, $headers);
?>
Reference:
http://php.net/manual/en/function.mail.php

my php code send empty email [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Please, this is php code that i used to send from HTML contact page, it works with out error but only i receive empty email! just the object of email i get and nothing else.
<?php
$email_address = $_POST["email"];
$tel_num = $_POST["tel"];
$first_name = $_POST["f_name"];
$last_name = $_POST["l_name"];
$text_send = $_POST["email_text"];
$to_com = "myemal#gmail.com" ;
$subject = " New eMail" ;
mail ($to_com, $subject, $text_send, " From: " . $email_address . $tel_num . $first_name .$last_name );
echo "Your Massage has been sent" ;
?>
So please i need some help?
Please look at this example from php.net
<?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);
?>
the line endings in the header (\r\n) are very important

Categories