After calling the mail function I would like to get the complete mail message that I just sent. Not just the subject and content field but also auto generated information such as Date and Content-Transfer-Encoding. That is the entire message. How do I do that?
PHP doesn't actually send the mail, so it won't know about any of that. All the mail() function does is pass your stuff on to the sendmail binary (or whatever SMTP server you use instead) and return whether or not that was successful. The rest is up to the SMTP server.
Best suggestion I can offer is to have the mail BCCd to an account you control and parse the desired info from there.
Related
I'm trying to send emails in a loop and it is working fine but it prints the result to page in one go rather one by one.
What I want is, it should print a response for every email sent. This is what I have so far:
//foreach loop
$Response = $ObjMail->send();
if ($Response) {
echo "Email Sent Successfully to $val[name] </br>";
} else {
echo "There was an error sending Email to $val[email]";
}
Depending on your $ObjMail, a "successfully send mail" generally will equate to
the sending mail server (i.e. smtp server) accepted the email or
the mail() function got called (actually read the doc, especially the return value part).
Email functions rarely return a very useful value, as long as the email being sent is at least somewhat plausible. It will even return true, if the email address doesn't exist, the email gets bounced, your smtp server is blacklisted, ...
The probable answer to your question: Your output is almost instantaneous by default, unless your local sendmail (the default on most hosts) call takes longer than a few microseconds, which it usually doesn't. Additionally, it doesn't say anything about the mails actually being sent. (And I assume, that you thought that was actually the case, it's not.)
My advice is, drop the stylish output and just send the mails. You can't be certain if they actually reached their target. If the $ObjMail actually returns an error, that would probably be wise to log somewhere, so that you don't repeatedly send to the same false address.
ok i edited some of the code and the submit button does what i want it to do which is post my php file. However even if i get errors like i left a required field blank it will still submit the form now heres the new code i changed to
onSubmit: function(invalid, event) {
event.isDefaultPrevented();
if (invalid) {
} else {
$.post('save.php', this.$form.serialize(), function(response) {
// do something with response
}, 'json');
}
$('#invalid')
.show()
.toggleClass('valid', ! invalid)
.text(invalid ? (invalid +' invalid fields') : 'All good!');
}
});
How do i code this so that it only submits my form when there are no invalid fields
Dont use mail() function of php it will send your mail to junk only. Instead use SMTP php mailer function.
Why we should use SMTP instead PHP mail():
SMTP log in to an actual account on a mailserver and send the mail through SMTP to another mail server. If the mail server is configured correctly, your mails are sent from an actual account on a mailserver and will not wind up flagged as spam.
Mail sent with the mail() function is sent with sendmail in most cases. There is no authentication going on and it will almost always be flagged as spam if you use the "From:" in the extra headers.
This is because if you take a look at an original email file in say, gmail, you will see the headers that are sent. You are actually sending from user#serverhostname.tld and not someone#example.com like you had told the mail function to do.
If you use SMTP and view the original the email is actually sent from someone#example.com
You can download SMTP class from:
https://code.google.com/a/apache-extras.org/p/phpmailer/source/browse/trunk/class.smtp.php?r=170
http://www.phpclasses.org/package/14-PHP-Sends-e-mail-messages-via-SMTP-protocol.html
have you tried just
mail($email_to, $email_subject, $email_message, $headers);
also declare all your variables at top of page
$email seems not to be declared
I have the following problem:
Using the PHP mail() function i send mails around.
But every so often the damn sendmail adds newlines to the message (Content-type: text/html; charset=utf-8).
Reading http://proquest.safaribooksonline.com/1565928393/ch20-77125 i figured out that this L= parameter is not set in sendmail. But i have no access to the mail server.
Is there a way ( By setting mail headers or something ) to skip the adding of these new line characters in the body of the mail )
Thanks in advance
I recommence to use a mailer class like PHPmailer, cause the build-in mail function don't match today's email standards, and you can easily configure the class for your needs.
I'm trying to handle bounced message and send to a responsible System Administrator.
I use CakePHP Email Component to send the message. On server side, I use postfix to transport the message.
function sendAsEmail($data) {
$Email->sendAs = 'html';
$Email->from = $user['Sender']['username'] . '#example.com';
$Email->return = Configure::read('App.systemAdminEmail');
$Email->bcc = array($data['Message']['recipient_text']);
$content = 'Some content';
$Email->send($content);
}
As you can see above, I set the $Email->return to sysadmin's email which it will send all the bounced message.
On postfix configuration, I tried creating a bounce.cf template and set bounce_template_file. http://www.howtoforge.com/configure-custom-postfix-bounce-messages
How do I get the bounced message and send it to System Administrator?
I think what you'll need to do is to use an SMTP (or I suppose POP3) connector for PHP. Then you'll basically have to create your own PHP email client that will login to the server, ask for the messages that have been bounced, and parse them appropriately.
I would think there would be a CakePHP component for this, but I can't find one.
I would recommend that you use an Envelope Header in your email. Otherwise you'll be stuck trying to parse the recipient server bounce, and those are very very inconsistent. If you use the VERP (variable envelope return protocol?) header, you can encode a unique hash into the email address which should be really easy to parse out in your PHPEmailClient.
More info on VERP: http://en.wikipedia.org/wiki/Variable_envelope_return_path
Cake-specific VERP stuff: http://www.mainelydesign.com/blog/view/setting-envelope-from-header-cakephp-email-component
I also highly recommend that you look into using SwiftMailer. It has a lot of plugins; you might find a base PHP SMTP client that you can easily modify to do what you need. http://swiftmailer.org/
I'm trying to sends mails in PHP. The code I used for sending a mail in CakePHP is given below. I get the message 'Simple Email Sent' in my web page but the mail is not delivered to my inbox. Am I missing something?
The values in the to, subject and link fields are set with the values entered in the user interface.
$this->set('to',$this->params['form']['to']);
$this->set('subject',$this->params['form']['subject']);
$this->set('link',$this->params['form']['link']);
$this->Email->to = to;
$this->Email->subject = subject;
$this->Email->from = 'someperson#somedomain.com';
$this->Email->delivery= 'mail';
$this->Email->sendAs='text';
$this->Email->template = 'simple_message';
//$this->Email->send(link);
if ( $this->Email->send(link) ) {
$this->Session->setFlash('Simple email sent');
} else {
$this->Session->setFlash('Simple email not sent');
}
On a Linux system, you'll probably have a sendmail script installed already, and PHP will use that. If this is what you have and it's not working, then I'd look for mail configuration problems in your Linux system itself.
On a Windows system, you'll need to configure the SMTP server you want PHP to send mail to. The normal way to do this is in php.ini. The instructions for this are here.
Unless you have set Email->delivery this should be the same for CakePHP - it should default to whatever PHP uses.
Note: If you are using your own Linux install, it could just be that your ISP is blocking port 25, which your mail server is using. In that case you'll need to configure linux to route email to your ISP's email server. Maybe this will help?
Since when is 'to' (line 4) a valid destination email address?
You need to use variable syntax for setting to 'to' line, and the 'subject' line. Those lines should read
$this->Email->to = to;
$this->Email->subject = subject;
Also, I believe there is an attribute in the Email component called error (I cannot find it in the documentation currently) that will help you debug. This may not be totally correct; I use the Email component with SMTP, and there is an attribute that gets set by the Email component called smtpError. I believe there is one called error that you can use to check for an error -- it should contain code that will tell you where your problem lies.
In case that's an incorrect statement, you can always do a var_dump( $this->Email ); after you try to send an email. That will dump the entire contents of the object, so you can see if you have set attributes correctly, and it should help you find out what the error attribute is named.