I read the other questions and solutions... which is why I'm frustrated. I didn't code this app, but I'm trying to retrofit it.
Currently it sends a confirmation email to the email address that gets entered by the customer in the field. When I comment out the mail($to,... part at the bottom, it breaks the confirmation email functionality, so I know I'm in the right place in the code.
I just want a duplicate email sent to my master email address. I thought if I just put another mail command under the functional one, but specified a static address instead of the $to var it would work... but it doesn't. I couldn't get the CC header functionality to work either based on other questions, so I thought just sending a duplicate email to another address would work just fine.
Here is the working code:
$sq2 = myQuery(" select * from admin ");
$dat2 = mysql_fetch_object($sq2);
$from = "reservations#duelingpianopiano.com";
$to = $email;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= "From: $from" . "\r\n";
$headers .= "Reply-To: $from" . "\r\n";
/*$headers = "From: $from" . "\r\n" .
"Reply-To: $from" . "\r\n" .
'X-Mailer: PHP/' . phpversion();*/
mail("vmvijitha#gmail.com", $subject, "sendemailtemplate($templateid,$tid,$userid,$modification)".$mailcontent, $headers);
//return;
mail($to, $subject, $mailcontent, $headers);
I feel like if I should just be able to add this line at the bottom to send the exact same email confirmation redundantly to my master email address for safe keeping.
mail("reservations#duelingpianopiano.com", $subject, $mailcontent, $headers);
Note: I think this line is an artifact from the original developer, and I can't tell whether it's working or not.
mail("vmvijitha#gmail.com", $subject,...
What am I assuming wrong?
insert multiple addresses using comma-separator in single variable.
$email_to = "xxx#one.com, xxx#two.com, xxx#three.com"
mail($email_to, $subject, $mailcontent, $headers);
Related
This question already has answers here:
php single and double quotes
(2 answers)
Closed 1 year ago.
I have set up the Sendmail client on my localhost xammp server running on my home pc but I am getting the following error:xx-xx-xx xx:xx:xx: Message is missing sender's address. I have gotten it to work when I use the hard code what I want to send, like so:
$msg = "hello world";
mail("example#gmail.com","My subject",$msg, 'From: admin#myEmailClient.com');
but when I try and implement my login validation script It does not work and I get the aforementioned error.
emailvalidation.php
$to = $email;
$sub = 'email verification';
$msg = "<a href='http://localhost/verify.php?vkey=$vkey'>account verification </a>";
$headers = "From: admin#myEmailClient.com \r\n";
$headers = "MIME-Version: 1.0". '\r\n';
$headers = "Content-type:text/html;charset=UTF-8 ". '\r\n';
mail($to, $sub, $msg, $headers);
my email variable is set by the user if that helps, I don't think its a problem with the items being parsed because when I check my database all rows are properly filled in.
thank you for your time
edit
I think it's a problem with the r\n parts, these are the parts that enable HTML in emails. when I get rid of them it works
I'm not sure if I should delete this question because of the speed I was able to solve it but I hope this helps someone who had the same problem as I did.
here is how I solved the problem
$message = "<a href='http://localhost/verify.php?vkey=$vkey'>account verification </a>";
$to = $email;
$subject = 'account validation';
$from = 'admin#myEmailClient.com';
$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();
if(mail($to, $subject, $message, $headers)){
echo 'Your mail has been sent successfully.';
} else{
header("location: index.PHP");
}
I got the solution from here. tutorial republic
i am having a issue with sending emails with cronjobs.
actually i need to send email to all the recently joined users
and so the emails are something like $to='acx1#xyz.com,acx2#xyz.com,acx3#xyz.com';
here i need to send the mail to all the receipts but not to let them know that i have sent this mail to all these persons in receipt basically BCC them
but the problem is that if i put the $to into BCC then what should i put in to function of mail
if to is empty then it may be spamed
i want to send this mail to all the receipts but when they check the headers they should see their email only
and one more issue please let me know if i am using correct headers ?
because sometimes my email is spammed by gmail
$from='tests.com';
$to='contact#test.com';
$message="<body> some html data with inline css </body>"
$subject="Hii this is test";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$headers .= "From: $from <contact#test.com>" . "\r\n";
$headers .= "Reply-To: contact#test.com" . "\r\n";
$headers .= 'BCC: acx1#xyz.com,acx2#xyz.com,acx3#xyz.com' . "\r\n";
mail($to, $subject, $message, $headers);
I am having a problem sending emails when I add header information.
However when I just remove the header parameter it works. What is wrong? Is it the code? Or some setting I need to change on the web server admin panel to say "Allow-Headers" or something?
I am trying to send to hotmail in case this has any relavance in determining the problem.
Any help would be greatly appreciated. Thanks.
Below Doesn't Send Email:
<?php
$to = 'iputmyrealemailhere#hotmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com';
mail($to, $subject, $message, $headers);
?>
Below Sends Email:
<?php
$to = 'iputmyrealemailhere#hotmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com';
mail($to, $subject, $message);
?>
I use these headers in my php mailing function and it works well. Note: I also use a third party mail-routing service to avoid having my mails marked as coming from a spammy IP. You might want to look into that also.
$headers = 'From: '.$from.'#foo.net' . "\r\n" .
'Reply-To: '.$from.'#foo.net' . "\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n";
I also use the optional fifth parameter to mail() to set the envelope address, e.g.:
$parameters = '-f '.$from.'#foo.net';
so the final call is:
mail($to, $subject, $message, $headers, $parameters);
You can just delete the "FROM:" from the headers list .. it prevents it in some hosts .But the real question then will be how ca I change the sent from email address to a specific email that I want
I am quite new to PHP and am experimenting with an online ordering website in php. I have come across a problem when trying to send a confirmation email using a 'cc'.
Every time an order is processed, the order always sends to the 'CC' address specified as the '$from' and the sender (the from) is what is specified in the '$to' section. In the email confirmation received, it only displays the from section and the 'to' and 'cc' are empty as demonstrated below:
From: **$_SESSION['od_email']**
To: *This space is empty*
CC: orders#business.co.uk
Can anyone help to point out where I am going wrong? I have attached the code below.
//THIS IS CODE FOR THE EMAIL WHICH IS AUTOMATICALLY SENT TO THE CUSTOMER AND THE BUSINESS WHEN AN ORDER IS SUCCESSFULLY COMPLETED
//define the receiver of the email
$to = $_SESSION['od_email'];
//define the subject of the email
$subject = 'Order Confirmation | Ref No for Order: '. $_SESSION['orderId'];
//define the message to be sent. Each line should be separated with \n
$message = 'test';
//Who the message is from
$from = "orders#business.co.uk";
$cc = "orders#business.co.uk";
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From:" . $from;
//bcc header going to the to go to the business as confirmation
$headers = "cc:" . $cc;
//send the email
$mail_sent = #mail( $to, $subject, $message, $headers );
What I need for it to show is:
From: **orders#business.co.uk**
To: **$_SESSION['od_email'];**
CC: **orders#business.co.uk**
Thanks in advance for any help given
When you're going to set the CC, you're overwriting what was in $headers. Try:
$headers = "From:" . $from . "\r\n";
$headers.= "Cc:" . $cc;
And if that doesn't help, there's always PHP's documentation on mail.
I would go all out with your headers and make sure you set everything you need to,
// 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: ' .$to. "\r\n";
$headers .= 'From: ' .$from. "\r\n";
$headers .= 'Cc: '.$cc. "\r\n";
also, I believe mail() needs a valid email address, I do not know how you have the email set before $_SESSION['od_email'] but if you are running a test and literally expecting $_SESSION['od_email'] to come with it that wont work, it will see it as a not valid email and return false, thus returning nothing. To further diagnose that problem tho we would need to know how $_SESSION['od_email'] is setup
EDIT
Okay I am pretty sure the issue is caused how you are setting up $_SESSION['od_email]' based on your comment below.
Note: I am assuming your database is $db, but if not you need to change $db to the prober name
Let's try this and see how it works
// Get Data from the Database
$query = "SELECT `od_email` FROM `tbl_order`";
$result = $db->query($query);
while ($data = $db->fetch_array($result)) {
// Set Up the SESSION email
$_SESSION['od_email'] = $data['od_email'];
// Prepare the Email
$to = $_SESSION['od_email'];
$subject = 'Order Confirmation | Ref No for Order: '. $_SESSION['orderId'];
$message = 'test';
$from = "orders#business.co.uk";
$cc = "orders#business.co.uk";
// 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: ' .$to. "\r\n";
$headers .= 'From: ' .$from. "\r\n";
$headers .= 'Cc: '.$cc. "\r\n";
// Send the email
mail($to,$subject,$message,$headers);
}
Couldn't he just add an #mail ? such as...
$mail_sent = #mail( $od_email, $subject, $message, $headers );
or
mail( $od_email, $subject, $message, $headers );
Replacing any variables.
Always worked for me.
hay
i used this code
$to = "mial#live.com,mail#yahoo.com";
$subject = "Mini-mass Emailer";
$message = "<a href='#'>Hello World</a>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Your Name <me#mydomain.com>' . "\r\n";
$headers .= 'Bcc: {$to}' . "\r\n";
if(mail($to, $subject, $message, $headers)){
echo 'ok';
}
but see what is happend
every user see the full list of the users
alt text http://img694.imageshack.us/img694/1289/21811933.gif
Your call to mail is passing the $to as the to parameter meaning those emails will be be in the to header try passing an empty string instead. You are passing the info into the bcc header so the email should still get to them that way.
That is because you have put all the users in the "to" line. You are also passing them into the "bcc" line too so just doing this may help you but as far as I know you need at least one address in the to line (although this may not be the case). It'll look pretty strange for each person doing it that way though.
The best way to avoid these issues would be to send the email multiple times, once to each user. To modify your code example to do this, I'd do something like the following:
$toAddresses = array("mial#live.com", "mail#yahoo.com");
$subject = "Mini-mass Emailer";
$message = "<a href='#'>Hello World</a>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Your Name <me#mydomain.com>' . "\r\n";
foreach ($toAddresses as $to) {
if(mail($to, $subject, $message, $headers)){
echo "OK - sent message to {$to}";
}
}
The easiest way is to take this Mail-Class of phpguru.org:
http://www.phpguru.org/static/htmlMimeMail5
There you can specify with setBcc() the addresses which should be "blind", it's pretty easy and works well. I use this class in every project.
Best Regards.