I working on a project in which i need to develop a functionality to send multiple emails to client with one click and i am adding customer id in one text box separating them with comma.
Please tell me how to do this problematically. Your advice
<?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);
?>
if you want to send the user as in db jus replace the $to address from db and place these code in loop.
php.net's mail function page explains this well
to be fair we all had to start somewhere. The problem with using "vanilla PHP mail" is that it is almost always used when people send mail as spam. So for 10 years mail servers haven't liked it. There are ways round it but to be brief:
To send Email via a webpage you "should"
have your mail server resolve RDNS
try to avoid cheap/free web hotels as mailserver hosts
use PHP PEAR MAIL (this is tricky/odd to install)
properly apply the correct headers for the mail in PEAR
Check below link may be help you.
http://www.quackit.com/php/tutorial/php_mail.cfm
Related
I have a PHP Contact form on a site I am hosing on our mediatemple grid server that was made with Rapidweaver. It works well except that the email it generates to our info#ourdomain.com is sent as serveradmin#ourdomain.com. I think the server is just using the trash/blackhole address. Any way to adjust my php or better yet, the server settings, to send the mail as the reply-to address that the user fills out on the contact form itself?
Why? Well Google hosts the email for this domain and I wanted to use their canned responses as an auto-responder. The problem of course, is that the auto-response goes to serveradmin#ourdomain.com and not the user's email address that he filled in on the form.
Thank you for the help!
-Hunter
You can add headers to your mail
<?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);
?>
see mail phpdoc
On my website we have a promotion going on where users input their name and e-mail and then we send them an e-mail with the same title, same text and an the voucher image at the end embedded/inserted onto the e-mail (not attached).
We thought we would be able to copy paste easily but over the past 6 weeks we have sent out over 1000 e-mails and this is undo able any more.
We have a php code that simply sends us their info.
Does anyone know what to add at the end of the php so that when someone inputs their e-mail and name we can just automatically send an e-mail to them with the "template" title, text and image?
I have tried many different things but most programmes are newsletter senders not auto-responders. Can't use gmail auto response either because we receive other e-mails for different things as well. We don't want to send the promo to everyone who e-mails us.
Any help?
Cheers.
Check Github for sendemail repository. It allows you to send emails through php. What you can do is that you can set sendemail repository in your project then whenever someone enter an email id run a php script.For configuring sendemail everything is provided on Github.
Link: https://github.com/mogaal/sendemail
Script will look something like this:
$message = "Thank you for your interest. We will get back to you as soon as possible.<br />Sincerely,<br />(My Name)";
$subject = "Confirmation";
$headers2 = "From: $webMaster\r\n";
$headers2 .= "Content-type: text/html\r\n";
mail($leademail, $subject, $message, $headers2);
Here is a sample script you can use without any third party classes.
<?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 add html content to the $message variable
I know how to use php mail() function. It works for me. But sometimes I am receiving blank emails with no message body, subject I mentioned in php mailer function with blank email id.
I did javascript validation for each and every form so that no field will be blank while submitting form.
After this validation also I am receiving blank email. Can any one please tell me why this is happening?
Note: I tried to submit form with blank spaces in text boxes but with blank spaces form is not submitting because of javascript validation.
EDIT:
code I used:
<?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);
?>
This is just an example from http://php.net/manual/en/function.mail.php
Without code it will be not possible to check what will be the issue. But below are some advice you can use :
1) Never use javascript validation, as it be bypassed, as it is client side not server side. Always use server side validation.
2) php mail function is good to use, but it is not feature rich. Try using swift or PhpMailer.
Hope this will help.
Using Mandrill email sending is perfect. No blank mails sent using Mandrill...
this may be a noobish question. I'd like to know if I can send emails from the server that say, domain1.com is associated with, as coming from domain2.com and also having the origin show as coming from domain2.com?
The reason I'd like to do this, is because I have an application I'm developing and would like to send emails from the domain, for example - maildomain.com instead of coming from domain.com
Emails are being sent with php's mail function.
Yes, you can:
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example-two.com' . "\r\n" .
'Reply-To: webmaster#example-two.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
You should set up some things, so the receiver doesn't mark it as spam though:
Set up DNS MX records with low priority for the receiving domain, pointing to sending server
Setup correct reverse DNS entries for sending server
..
The "From" address in an email is entirely arbitrary. As long as you have permission to submit mail to a server's queue, you can put any From address in it that you want. president#whitehouse.gov, julian#wikileaks.org, etc.
To do this with PHP's mail() function, use *$additional_headers*. For example:
$to = "whoever#example.com";
$subject = "This is an example!";
$message = "Hello,\n\nThis is message body.\n\nIsn't that nice?\n\n";
$headers = "From: El Presidente <president#whitehouse.gov>\r\n"
. "X-foo: bar\r\n";
$result = mail($to, $subject, $message, $headers);
Possible? Yes is sure is. See the below example from PHP.net. However, I'm going to put a little piece of fine print here, as I think you might run into some trouble, and I want to make it easier for you in the future. ;) Your current webhost may block this, I've never seen it, but I've heard it can happen. Also, there is a thing called SPF, or Sender Policy Framework, that is a DNS record that you can set to determine what servers can send on your behalf. Many servers that could receive your mail, and especially GMail check for valid SPF. All you have to do is add a TXT record on your name server for domain.com. It should look something like this: v=spf1 mx a:maildomain.com -all. This says any records that have an MX record set up, and the IPs that are resolved from maildomain.com are valid 'non-spam'. Also, you will to fail any other mail origin.
<?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);
?>
If the mail server is an open mail relay then yes, you can send from a different domain. It is of course seen as a vulnerability as spammers can use it to send out junk mail. The configuration of the mail server to get this functionality depends on its platform but you can usually test a server's ability to freely relay messages by telneting to the server on port 25 and doing an ehlo test.
Whenever I send an email to my clients, their inbox shows the email details of my server that is hosting my website, instead of the email I mention in the from variable. something like this
From John Smith username704#sadalsuud.hostingService.com
What I want is this
From accounts#myWebsite.com
Help will be appreiated. I am clueless as to whether it is a question more suitable for mentioning in Serverfault. If so, then let me know.
$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);
What Narek says sometimes works, but kind of depends of the settings. I had a simular problem in the past using mail() and whatever i tried, i sometimes just got the hostname. It appeared to be a server(settings) issue.
What did help me, was using Swiftmailer over SMTP ( http://swiftmailer.org/ ) instead. You should give it a try, it's a very nice script.