why does it always use headers in php with email sending - php

My question is why people use headers with email sending in php. I know we can send some information to browser before it renders content. But when we show images on email body , I notice that it uses php headers. Can't we do it without headers? Because that is rendring html on a web browser.

You need to tell browser what type of content are we rendering .. e.g is it plain text , html page , pdf file etc ...
So when ever we want to have html in our email body we need to tell browser about it so that it can be properly handled

No. Sending an Email must contain a from header. It is well written in php.net
When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini.
Failing to do this will result in an error message similar to Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing. The From header sets also Return-Path under Windows.
You can set it in php.ini if you dont want to use additional headers.

Related

PHPmailer custom header set, but not shown on delivery

I am using PHPMailer6.2.0 and I am having issues setting the return path.
I have added the custom header via PHPmailer function addCustomHeader()
$mail->addCustomHeader("Return-Path", $fromemail);
and for debugging I have printed out the header content in \PHPMailer\PHPMailer.php function mailSend($header, $body) on line 1794;
var_export($header);
die();
this prints out the header content before it will be sent and it verifies that the custom header return-path is set correctly, however in action, when i receive an email to my outlook, the header return path callbacks to the domains default email user#domain.com. Perhaps this is not the last place before the email is sent and it gets lost later on?
I am using DirectAdmin as my server manager
Stop right there! Senders should not set a return-path header. That header is added by the receiver, and what goes into it is dependent on the SMTP envelope sender, the address that's used in the SMTP MAIL FROM command that delivered the message. Setting this header as a sender is a straightforward contravention of the RFCs. So what should you do instead? Set the envelope sender, and in PHPMailer you do that like this:
$mail->Sender = $fromemail;
Even when you do this, whether the server your'e sending through will accept it is a different matter. For example gmail will not allow you to use anything other than your account username address or predefined aliases, not arbitrary addresses.
Have you seen the comment above in mailSend function?
The sender gets turned into a return-path header by the receiver!
<?php
$params = null;
//This sets the SMTP envelope sender which gets turned into a return-path header by the receiver
//A space after `-f` is optional, but there is a long history of its presence
//causing problems, so we don't use one
//Exim docs: http://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_exim_command_line.html
//Sendmail docs: http://www.sendmail.org/~ca/email/man/sendmail.html
//Qmail docs: http://www.qmail.org/man/man8/qmail-inject.html
//Example problem: https://www.drupal.org/node/1057954
// CVE-2016-10033, CVE-2016-10045: Don't pass -f if characters will be escaped.
if (!empty($this->Sender) && static::validateAddress($this->Sender) && self::isShellSafe($this->Sender)) {
$params = sprintf('-f%s', $this->Sender);
}
I do not think you should set the return-path header by yourself. I believe PHPMailer uses the sender to handle this automatically. But correct me if i am wrong.

Gmail telling what I am using to send email

When I send an email using phpmailer to gmail, and I look the email source, I see the following next to the "from" field:
"Using PHPMailer 6.1.7 (https://github.com/PHPMailer/PHPMailer)"
For security reasons I'd prefer to remove that if it's possible, but I don't know if this is Gmail being smart or phpmailer appending it to every email message I send.
How can I remove it?
Thanks
This appears in the X-Mailer header. As per the docs, you can remove this header altogether by setting it to a space, like this:
$mail->XMailer = ' ';
If it's appearing somewhere else, I'll need to see the rest of your code and the headers of a message you've received in gmail.

corrupted link - send email - exchange server - CodeIgniter

I need to send a link within HTML email using CodeIgniter.
first trial:-
send an email to using Gmail server, then the link will be sent successfully without any corruption.
Second trial:
I am using Microsoft Exchange Server.
when sending the link within the HTML email, the link will be received corruptly!!
I don't know why? Then the problem occurred when using only Exchange server.
correct link
http://000.00.0.00/s/admin/r?i=7&e=hana#dom.edu.com
corrupted link
http://000.00.0.00/s/admin/r?i=7&e=hana#do=.edu.com
If I put it within a href tag
correct link
http://000.00.0.00/s/admin/r?i=7&e=2
corrected link
http://000.00.0.00/s/admin/r=i=7&e=2
My IP= 000.00.0.00, it is not the actual but it is just an example
You have to change the crlf setting to use Exchange as an SMTP server.
Add $this->email->set_crlf( "\r\n" );to your controller or add $config['crlf'] = "\r\n"; to your email config file!
The equal signs getting substituted into your email message are a dead giveaway that the end of line character is the issue.

Zend Mail sending with headers shown in body and header section in mail clients

I am using Zend Framework to send mail.
It's doing something very odd, the content type, content dispostion, MIME version and content type encoding are all showing up in the header section (under the subject) of the email in GMail and in Outlook.
The content of the email was also being included twice in the email, once as plain text and once as HTML. I stopped this by just using setBodyText() instead of using setBodyHtml() too. I had seen somewhere that you can use both. Now I just use setBodyText() like this
$mail = new Zend_Mail('utf-8');
$mail->addTo("mail#mail.com");
$mail->setSubject("Registration info");
$mail->setFrom('do-not-reply#mail.com', "A Name");
$mail->setBodyText($this->view->render('emails/register.phtml'));
$mail->send();
This has been solved. It was an error with the host receiving the email. The fact it was in Outlook or GMail made no difference as the error was with the host.

PHP mail, header and call to mail() function, what has override?

I've been struggling with low level mail in PHP and I know I should be using a library for this, but that's not an option right now.
When doing mail in PHP, you can manually set additional headers, like From, Cc and Bcc, but you can also set Subject, To and a Body. When you call the function you pass the headers along to the mail() function, but that function also "asks for" a Subject, body and To.
My question then is: how does PHP handle the double intention in this? If you manually set the header to have Subject : foo, but then in the call to mail pass 'foo' along as the subject...?
I can't read C, so opening up PHP source probably won't help me here.
Thanks!
Well, no need to read C, just test it: it's a one liner :)
If you specify a subject in both places PHP does nothing special: you get an e-mail message with two subject headers. Which one gets displayed in your e-mail client is something I don't know; perhaps it's defined in e-mail protocols, perhaps it's a per-client choice.
About the "To" header, PHP sets one from the $to parameter when you don't specify a header manually; if you set one, your header prevails.
It's worth noting that the "From" and "To" headers have no effect in who sends and receives the message: they're purely informative. Mail server software requires senders and recipients to be specified implicitly; headers are not parsed for this purpose.
The question here seems to be if you specify a 'To' or a 'Subject' in the additional headers, what appears in the email produced.
If so, then the simple answer is to test it:
$add_to ='to: "added" <user#example.com>"; // substituting your email address
$param_to ='"param" <user#example.com>";
$add_subj ='subject: Subject in header';
$param_subj='Subject in param';
$add_hdr=$add_to . "\n" . $add_subj;
mail($param_to, $param_subj, "body - test", $add_hdr);
Then have a look at the message you get back.
C.
Right way - don't use Subject, To and a Body in headers. You can remove it from heders with regular expression, if you take headers as is. Other way - you can use PEAR library - http://pear.php.net/manual/en/package.mail.mail-mime.example.php

Categories