Echoing image in php mail , showing error - php

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.

Related

Mail Function is giving false return in PHP

I have tried sending email from a basic html form by php mail() function and It has given me false return
Code:
<?php
if(isset($_POST['submit'])){
$title = $_POST['title'];
$name = $_POST['first_name'];
$name1 = $_POST['last_name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$company=$_POST['lead_object'];
$skype= $_POST['skype_id'];
$to = 'himanshu#webkidukan.com';
$subject = 'Advertiser Form Details';
$from = 'ssing648#gmail.com';
// 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";
// Create email headers
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
// Compose a simple HTML email message
$message = '<html><body>';
$message .= '<h1 style="color:#f40;">Hi Sir</h1>';
$message .= '<p style="color:#080;font-size:18px;">Details of Advertiser Form</p>';
$message .= '<p style="color:#080;font-size:18px;"><?php $title . " " . $name . " " . "?>wrote the following:"<?php . "\n\n" . $name . "\n\n" . $name1 . "\n\n" .$email . "\n\n" .$phone . "\n\n" .$company. "\n\n" .$skype. "\n\n"?> </p>';
$message .= '</body></html>';
$t = mail($to, $from, $message, $headers,$subject);
var_dump($t);exit;
if ($t) {
echo "Mail Sent. Thank you " . $name . " .We will contact you shortly.";
}else{
echo "Failed to send email. Please try again later";
}
echo "<script type='text/javascript'>alert('Thanks for filling out our form! We will look over your message and get back to you soon.')</script>";
echo "<script> window.location.href = 'advertiser.php';</script>";
}
?>
I have this issue in three forms together , hence posting one for the understanding the mistake, that I am doing. Can anyone of you help me with the same.Or should I go for the SMTP mail option.Also I am sending the form details in mail to the user.So also check that the way to send the flyer is right or not.
There are some unwanted PHP tags while appending message. try like this
$message = '<html><body>';
$message .= '<h1 style="color:#f40;">Hi Sir</h1>';
$message .= '<p style="color:#080;font-size:18px;">Details of Advertiser Form</p>';
$message .= '<p style="color:#080;font-size:18px;">'.$title." ".$name." wrote the following:"."\n\n".$name."\n\n".$name1."\n\n".$email."\n\n".$phone."\n\n".$company."\n\n".$skype."\n\n".'</p>';
$message .= '</body></html>';

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

Inquiries : Sometime getting, sometimes not?

I have added a quick contact form in every page so clients can easily get in touch. However, three different things are happening as below:
sometimes getting inquiries from client. (Genuine I can say, we worked together)
sometimes getting blank message. with Unknown sender every alternate day.
Getting nothing. (Whenever I am trying to check whether all pages working or not. I am not getting email on first time. (Sometimes second, third, fourth time works).
My code is as follows:
PHP script I am using:
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>' some message '
);
//echo '<pre>';print_r($_POST);exit;
$name = #trim(stripslashes($_POST['name']));
$email_from = #trim($_POST['email']);
$websitelink = #trim(stripslashes($_POST['websitelink']));
$subject = 'iMarketingJunkies: Inquiry';
$message = #trim(stripslashes($_POST['message']));
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <'.$email_from.'>' . "\r\n";
//$email_from = $email;
$email_to = 'myemail#email.com';//replace with your email
$body = 'Name: ' . $name . '<br><br>' . 'Email: ' . $email_from . '<br><br>' . 'URL: ' . $websitelink . '<br><br>' . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, $headers);
echo json_encode($status);
die;
?>
Can anybody please help me to get rid of this. I have tested all pages and I am sure we can't add submit button without any data. I am using Cloudfare.
Thank you

How to send HTML message using PHP?

I'm trying to send the message as HTML, but it's arrived as XML Escape!!
Example in screenshot:
second problem is, if i typing the subject in "Arabic language" it's encoded in ANSI.
but if i test to send the same message via Gmail the subject be fine, but the content arrived as XML Escape!!
PHP CODE:
<?php
if(isset($_POST['submit'])){
$to = "email#gmail.com";
$from = $_POST['email'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$subject = $first_name . " " . $last_name . " " . "\n\n";
$message = '<html><body>';
$message .= '<h1>Hello, World!</h1>';
$message .= '</body></html>';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=UTF-8" . "\r\n";
$headers = "From: Brand Name <info#my-dmoain.me>" . "\r\n";
mail($to,$subject,$message,$headers,"-f info#my-dmoain.me");
echo "Thanks";
}
?>
I cant figure out what is wrong.
Thanks
Add concat shorthand .= to this line:
$headers = "From: Ali Najm <ali-najm#iraqnaa.me>" . "\r\n";
You're reassigning $headers var.
Sending nice html with php

How to make a text bold in PHP mail()?

I would like to mail some text as bold in my email content. I have used the following code
$to = 'some#gmail.com';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=UTF-8' . "\r\n";
$from = $param['email']; // this is the sender's Email address
$headers = "From:" . $from;
$name = $param['name'];
$subject = "Test";
$message = "message.\n\n"
."<b>Name:</b> ".$name . "\n\n"
."Adress: \n"
.$param['address'] . "\n"
.$param['zip'] . ", "
.$param['postal_area'] . "\n\n"
."E-post: ".$param['email'] . "\n\n\n"
mail($to,$subject,$message,$headers);
I have used <strong> also instead of <b> tag, but nothing works.
I get mail in the below format :
<b>Namn:</b> some name
Adress:
BorĂ¥s, Sweden
4837, Boras
E-post: somemail#gmail.com
You are overwriting the header variable again. You need to append to it.
$headers .= "From:" . $from; //You forgot to concatenate here...
// ---^ //Add the .
Try setting the font weight property in a span:
$message = "E-post: <span style='font-weight:strong;'>".$param['email']."</span>";
But also see other reply, you are overwriting the header so it is not reading the message as HTML.

Categories