Viewed   179 times

I am using PHP with Apache on Linux, with Sendmail. I use the PHP mail function. The email is sent, but the envelope has the [email protected] in MAIL FROM (example [email protected]) and some remote mail servers reject this because the domain doesn't exist (obviously). Using mail, can I force it to change the envelope MAIL FROM?

EDIT: If I add a header in the fourth field of the mail() function, that changes the From field in the headers of the body of the message, and DOES NOT change the envelope MAIL FROM.

I can force it by spawning sendmail with sendmail -t -odb -oi [email protected] and piping the email contents to it. Is this a better approach?

Is there a better, simpler, more PHP appropriate way of doing this?

EDIT: The bottom line is I should have RTM. Thanks for the answers folks, the fifth parameter works and all is well.



mail() has a 4th and 5th parameter (optional). The 5th argument is what should be passed as options directly to sendmail. I use the following:

mail('[email protected]','subject!','body!','From: [email protected]','-f [email protected]');
Thursday, December 8, 2022

You have $headers .= '...'; followed by $headers = '...';; the second line is overwriting the first.

Just put the $headers .= "Bcc: $emailListrn"; say after the Content-type line and it should be fine.

On a side note, the To is generally required; mail servers might mark your message as spam otherwise.

$headers  = "From: [email protected]" .
  "X-Mailer: phprn";
$headers .= "MIME-Version: 1.0rn";
$headers .= "Content-Type: text/html; charset=ISO-8859-1rn";
$headers .= "Bcc: $emailListrn";
Sunday, December 25, 2022

There are various ways this can be done. 1. Convert your CSS to PHP, i.e. CSS is generated, but everything can be dynamic - probably overkill for a few colours 2. Overwrite the styles in the stylesheet

The simplest way, probably not the best though is number 2, over write the style after the stylesheet with the new colour.

i.e (sudo code)

<style ... src="..." />
// from db
#custom { background: #<?php echo $colour; ?> }


Monday, September 19, 2022


HttpURLConnection has no JavaScript support, but a needed cookie is generated using JavaScript.

Your call

String reqUrl = "";
URL url = new URL(reqUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

fails, because the cookie __test is missing.


From a first glance at the JavaScript source the cookie seems to be constant for a given url, so it might be enough to set for a constant cookie:

String cookie = "__test=2bf7c15501c0ec57f8e41cb84871a69c";

URL url = new URL(reqUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Cookie", cookie);

Alternative: Using a WebView we can grab the cookie, so this is the preferable approach, since it will not break, if the cookie changes and it is not much of a time delay:

protected void onCreate(Bundle savedInstanceState) {


    if(cookie!=null) {
        new GetContacts().execute();

private void getCookie(){
    WebView wv = new WebView(getApplicationContext());
    cookie = CookieManager.getInstance().getCookie("");

and set it as in above example:

conn.setRequestProperty("Cookie", cookie);

Output in logcat

Response from url: [{"0":"1","id":"1","1":"pertanyaan ke 1","ask":"pertanyaan ke 1"},{"0":"2","id":"2","1":"pertanyaan ke 2","ask":"pertanyaan ke 2"},{"0":"3","id":"3","1":"pertanyaan ke 3","ask":"pertanyaan ke 3"},{"0":"4","id":"4","1":"pertanyaan ke 4","ask":"pertanyaan ke 4"},{"0":"5","id":"5","1":"pertanyaan ke 5","ask":"pertanyaan ke 5"}]
Friday, October 21, 2022

PHPMailer is the best to use for email.

checkout some below links which will help you in future also:

  1. File Attachments in PHP Mail with PHPMailer
  2. php mailer attachments
  3. attachments using phpMailer
  4. PHPMailer Tutorial
  5. A Simple Example : Sending Email with Attachment Using Phpmailer
  6. PHP send email with multiple attachments with PHPMailer with SMTP Authentication
  7. Sending email with multiple attachments with PHP

may this help you.

Saturday, November 5, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :