0

i have a PHP variable that i construct like:

$msg_gifted='<body style="border:3px solid 
black;padding:5rem;width:1000px;margin:auto;margin-top:30px;text-
align:center;">';
$msg_gifted.='<img src="/logo.png">';
$msg_gifted.='<h1>It is a mail </h1>';
$msg_gifted.='<p>From: ';
$msg_gifted.=$_POST["useremail"];
$msg_gifted.='</p>';
$msg_gifted.='<p>Amount: GBP';
$msg_gifted.=$_POST["amount"];
$msg_gifted.='<Some text </p>';

then i am sending this variable with mail

 mail($recipient_gifted,$subject_gifted,$msg_gifted,$mailheaders_gifted);

everything works fine. When i am adding some more staff to the variable then for some reason the mail never arrives

 $msg_gifted='<body style="border:3px solid 
black;padding:5rem;width:1000px;margin:auto;margin-top:30px;text-
align:center;">';
$msg_gifted.='<img src="/logo.png">';
$msg_gifted.='<h1>It is a mail </h1>';
$msg_gifted.='<p>From: ';
$msg_gifted.=$_POST["useremail"];
$msg_gifted.='</p>';
$msg_gifted.='<p>Amount: GBP';
$msg_gifted.=$_POST["amount"];
$msg_gifted.='<p>Some Text</p>';

$msg_gifted.='<p>';
$msg_gifted.='1000';
$msg_gifted.='</p>';

is there a limit for the variables?

10
  • No, its just a html in form of string stored in variable, it looks fine Commented Oct 13, 2017 at 9:08
  • why when i add the last 3 lines it fails to send? Commented Oct 13, 2017 at 9:08
  • You have issue with 1000 ? Commented Oct 13, 2017 at 9:09
  • 4
    Perhaps it is being bounced due to spam filters or some other rules. It seems extremely unlikely that those 3 lines would make it fail to send, I think you are just not receiving it. Commented Oct 13, 2017 at 9:10
  • 1
    try debugging mail function . Iike $k=mail($params); var_dump($k);die; Also check server logs ..You may get a clue from there Commented Oct 13, 2017 at 9:13

2 Answers 2

2

You should consider using something like PHPMailer or SwiftMailer for sending E-Mails.

Most likely you got something wrong with the headers of the E-Mail. It's difficult to get them right, especially, when using mail for the first time.

Also, as far as I know, there's no such thing as a variable limit for mail(), have you already checked your server error logs?

Greetings

Edit:
As I thought it's a header based error.

i figured out it has to do with the headers. the whole mail headers variable is:

$mailheaders_gifted = "From: " . $support_email . "\r\n";
$mailheaders_gifted .= "Reply-To: ". $support_email . "\r\n";
$mailheaders_gifted .= "MIME-Version: 1.0\r\n";
$mailheaders_gifted .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

I also tried :

"Content-type:text/html;charset=UTF-8" . "\r\n";

I still recommend to use one of the libraries I mentioned above.

Following from the PHP Docs for the mail function could solve the problem:

Note:
If messages are not received, try using a LF (\n) only. Some Unix mail transfer agents (most notably » qmail) replace LF by CRLF automatically (which leads to doubling CR if CRLF is used). This should be a last resort, as it does not comply with » RFC 2822.

Sign up to request clarification or add additional context in comments.

6 Comments

hi, are the above libraries standard or should i install them on my server?
Neither PHPMailer nor SwiftMailer are PHP standard libraries. You could install them with Composer or without composer. I highly recommend Composer when working with libraries in PHP.
I am working on a shared server building a form that sends the above e-mails. Is this possible to have them available or i should ask the technical guys install it for me? I dont have SSH access
I don't think that they will install Composer on this shared server for you; same for "webspace" offers across the web. You could install Composer on your local machine and upload the project via FTP to your web directory. It isn't best practice, but better then working without Composer. There a many good tutorials for working with Composer and also some for working without Composer when using PHPMailer etc.
the whole mail headers variable is: $mailheaders_gifted = "From: " . $support_email . "\r\n"; $mailheaders_gifted .= "Reply-To: ". $support_email . "\r\n"; $mailheaders_gifted .= "MIME-Version: 1.0\r\n"; $mailheaders_gifted .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
|
0

I finally managed to solve this. it was not a problem of how to setup the variable, but how to setup the headers. i needed to edit my headers like:

$mailheaders_gifted[] = 'MIME-Version: 1.0';
$mailheaders_gifted[] = 'Content-type: text/html; charset=iso-8859-1';
$mailheaders_gifted[] = 'From: My Web Site <[email protected]>';

then the mail function should be:

mail($recipient_gifted,$subject_gifted,$msg_gifted,implode("\r\n",$mailheaders_gifted));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.