How can i have a paragraph in my mail() [duplicate] - php

This question already has answers here:
Send email with PHP from html form on submit with the same script
(8 answers)
Closed 5 years ago.
Hi im working on a button that will open a new mail tab with the predefined text but i cant have any paragraphs in the mail.
I tried \n and <br> nothing works...
$message .= '<html>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Annehmen →
</td>
</tr>
</table>
</td>
</tr>
</table>
</html>';

I understand your question now: you are passing the text through a URL, so you need to use urlencode() to preserve the newlines.
$body = urlencode('Servus, vielen Dank fuer deine Reservierungsanfrage, hiermit bestaetigen wir deine gewueschte Reservierung am ' . $date . ' um ' . $time . ' fuer ' . $amount . "\n" . ' Personen.');

Use \r\n instead of \n or <br>.
Also, if you specify the mail type as HTML, then <br> should work.

As per RFC2368 which defines mailto:, further reinforced by an example in RFC1738, it is explicitly stated that the only valid way to generate a line break is with %0D%0A.
Please try below code,
$message .= '<html>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Annehmen →
</td>
</tr>
</table>
</td>
</tr>
</table>
</html>';
this question too of stackoverflow,
enter link description here

Related

Is it possible to create html elements for email templates via a loop?

I have a working phpMailer that sends out various email templates; emails for "forgot password" or "forgot username", etc.
I was curious if it was possible to create html elements via a while loop? (I'm sorry I can't explain it so well, so here is my current code. It works but it just doesn't do the loop that I want it to do. It sends an email with just one username).
for ($i=0; $i < count($w_user_id_infos); $i++) {
$replaceUsername = $w_user_id_infos[$i]["login_cd"];;
for ($j=0; $j < count($w_user_id_infos[$i]["customer_info"]); $j++) {
$w_customer_name1_text = $w_user_id_infos[$i]["customer_info"][$j]["customer_name1_text"];
$w_customer_name2_text = $w_user_id_infos[$i]["customer_info"][$j]["customer_name2_text"];
$w_body .= ($j + 1) . " " . $w_customer_name1_text . " / " . $w_customer_name2_text . "<br>";
$replacementValues = [
$w_customer_name1_text,
$w_customer_name2_text
];
$templateValues = [
"%username%",
"%company%",
"%company2%"
];
}
array_splice($replacementValues, 0, 0, $replaceUsername);
$w_body = file_get_contents('../../../framework/src/function/html_templates/forgot_username.html');
$w_body = str_replace($templateValues, $replacementValues, $w_body);
}
$data = explode(',', $_SESSION['icon_data']);
$image_data = base64_decode($data[1]);
f_common_send_mail($w_addr, $w_subject, $w_body, $image_data);
So, for our program, a user can create multiple accounts with a single email address. The goal with the loop problem is, if that user forgot one (or more) of their usernames, they can click "forgot username" and after they enter their email address, an email would be sent with all of their usernames.
This is the html template.
<table bgcolor="#ffffff" class="table_content" align="center" cellpadding="0" cellspacing="0" border="0">
<!-- HEAD -->
<tr>
<td bgcolor="#ffffff" class="header_detail_area">
<table width="10%" align="left" border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="padding: 0 20px 20px 0;">
<img src="cid:img" style="width: 65px; height: 65px; border-radius: 50%;">
</td>
</tr>
</table>
<table width="70%" align="left" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="header_info">
STRUCT - ユーザー名の確認のお知らせ
</td>
</tr>
</table>
</td>
</tr>
<!-- HEAD END -->
<!-- USER INFO -->
<tr>
<td class="user_detail_area borderbottom">
<table width="97%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="user_info">
ユーザー名の確認を受け付けました。本メールアドレスには以下のユーザー名が紐づいています。
</td>
</tr>
<tr>
<td class="user_info_blockquote">
<p class="blockquote">
<font style="color: #03abf2"> ユーザー名: </font> %username% <br>
<font style="color: #03abf2"> 所属会社: </font> %company% / %company2%
</p>
</td>
</tr>
<tr><td><br></td></tr>
</table>
</td>
</tr>
<!-- USER INFO END -->
<!-- FOOTER DETAILS -->
<tr>
<td class="footer_detail_area" bgcolor="#31424b">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<img src="cid:Logo" width="200">
</td>
</tr>
</table>
</td>
</tr>
<!-- FOOTER DETAILS END -->
</table>
</td>
</tr>
</table>
I want to know if this is possible? To somehow create more of the %username% based on the for loop?
The user currently receives the email with just the one username that is registered with their email address.
Is it possible to manipulate the html email template with a loop? My thought is that since it's using an already-made email template, it won't have the chance to add any more html elements? even if I added some string literals, I don't think I can loop inside a string literal.
Thank you in advance.
My solution:
I replaced the whole tr that needed to be looped:
<tr>
<td class="user_info_blockquote">
<p class="blockquote">
<font style="color: #03abf2"> ユーザー名: </font> %username% <br>
<font style="color: #03abf2"> 所属会社: </font> %company% / %company2%
</p>
</td>
</tr>
changed to just:
%userElement%
then I created that html element in my loop like so:
$userElement .=
'<tr>
<td class="user_info_blockquote">
<p class="blockquote">
<font style="color: #03abf2"> ユーザー名: </font> '. $replaceUsername .' <br>
<font style="color: #03abf2"> 所属会社: </font> '. $w_customer_name1_text .' / '. $w_customer_name2_text .'
</p>
</td>
</tr>';
Worked like a charm.

HTML Purifier for webmail

I'm working on small webmail client. For safely embedding html I want to use HTML Purifier (BTW: it's a good idea?).
I checked it with several emails and some problems. One email (from Google) is having something like this:
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="4%">
<td width="92%" style="padding-top:18px; padding-bottom:10px; opacity:0.7">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<td width="30%">
<img style="display:inline-block;" height="26" src="https://www.gstatic.com/local/guides/email/images/photo-impact/googlelogo_light_clr-f040d5d9.png">
<td>
<td width="70%" style="text-align:right">
</td>
</tbody>
</table>
Converts to:
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="4%">
</td><td width="92%" style="padding-top:18px;padding-bottom:10px;opacity:.7;">
</td><td width="30%">
<img style="display:inline-block;" height="26" src="https://www.gstatic.com/local/guides/email/images/photo-impact/googlelogo_light_clr-f040d5d9.png" alt="googlelogo_light_clr-f040d5d9.png">
</td><td>
</td><td width="70%" style="text-align:right;">
</td>
</tr></table>
I don't know why it remove second <table> tag (also it close wrong <td> and removes <tbody>). Is it possible to change HTML Purifier to make it work for those situations?

split content of string by space to new line [duplicate]

This question already has answers here:
replace space with new line
(2 answers)
Closed 7 years ago.
I have $str= "ns.kimsufi.com ks392904.kimsufi.com ks392904.kimsufi.com"
I want to have them like that as string :
$str= "ns.kimsufi.com
ks392904.kimsufi.com
ks392904.kimsufi.com"
What is the easiest way to do such thing in PHP ?
Problem didn't solved...
Here is whole code :
<?php
$str= 'res Athéna 2 rue Henri Bergson<br/>
<b>Tech City: </b>STRASBOURG<br/>
<b>Tech State/Province:<br/>
</b><b>Tech Postal Code: </b>67200<br/>
<b>Tech Country: </b>FR<br/>
<b>Tech Phone: </b>+33.679795486<br/>
<b>Tech Phone Ext:<br/>
</b><b>Tech Fax:<br/>
</b><b>Tech Fax Ext:<br/>
</b><b>Tech Email: </b>fnt25qgfilw16kj60goe#h.o-w-o.info<br/>
<b>Name Server: </b>ns.kimsufi.com<br/>
<b>Name Server: </b>ks392904.kimsufi.com<br/>
<b>Name Server: </b>ks392904.kimsufi.com<br/>
<b>DNSSEC: </b>unsigned<br/>
<b>URL of the ICANN WHOIS Data Problem Reporting System:<br/>
</b>http://wdprs.internic.net/<br/>
>>> Last update of WHOIS database: 2015-06-07T10:20:36.0Z <br />
</td></tr>
</table><br />
<form name="queryform" method="post" action="/index.php">
<table cellpadding="6" cellspacing="0" border="0" width="540" dir="ltr">
<tr><td bgcolor="#92CAFE">
<table width="100%" cellpadding="0" cellspacing="0" border="0" dir="ltr">
<tr class="upperrow">
<td align="left" valign="top" nowrap="nowrap"><font face="Arial" size="+0"><b>Enter any domain name:</b></font></td>
</tr>
<tr class="middlerow">
<td align="center" valign="middle" nowrap="nowrap"><input type="text" name="query" value="" class="queryinput" /> <input type="submit" name="submit" value="Check Domain" /></td>
</tr>
<tr class="lowerrow">
<td align="right" valign="bottom"></td>
</tr>
</table>';
$dom = new DOMDocument;
#$dom->loadHTML($str);
$xp = new DOMXPath($dom);
$links = $xp->query('//b[text()="Name Server: "]/following-sibling::a[1]');
foreach ($links as $link) {
$newlink = $link->nodeValue . PHP_EOL;
$newlink = str_replace(' ', "\n", $newlink);
echo $newlink;
}
?>
it still echo like that :
ns.kimsufi.com ks392904.kimsufi.com ks392904.kimsufi.com
what is the problem ?
if its not space between them what it is ?
any chance to change the code without using str_replace ?
You could use str_replace to do that.
$str = str_replace(" ", "\n", $str);
echo $str;
\n will do a linebreak.
Just replace space with newline character.
preg_replace('~\h~', '\n', $str);
str_replace alone would be enough for this job. But if you want to replace also the tabs, you must go with the above.
str_replace(' ', "\n", $str);

Get data from table using regex php

I want to extract some data from a table using php preg_match_all(). I have the html as under,
I want to get the values in td,
say Product code: RC063154016.
How can I do that? I don'y have any experience with regex,
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><span>Product code:</span> RC063154016</td>
<td><span>Gender:</span> Female</td>
</tr>
</tbody>
</table>
Use DomDocument
$str = <<<STR
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><span>Product code:</span> RC063154016</td>
<td><span>Gender:</span> Female</td>
</tr>
</tbody>
</table>
STR;
$dom = new DOMDocument();
#$dom->loadHTML($str);
$tds = $dom->getElementsByTagName('td');
foreach($tds as $td){
echo $td->nodeValue . '<br>';
}
OUTPUT
Product code: RC063154016
Gender: Female
This should do for you:
preg_match_all('|<td><span>Product code:</span>([^<]*)</td>|', $html, $match);
But if you think there can be random white spaces around tags, then this one:
preg_match_all('|<td>\s*<span>\s*Product code:\s*</span>([^<]*)</td>|', $html, $match);
$data = <<<HTML
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><span>Product code:</span> RC063154016</td>
<td><span>Gender:</span> Female</td>
</tr>
</tbody>
</table>
HTML;
if(preg_match_all('#<td>\s*<span>Product code:</span>\s*([^<]*)</td>#i', $data, $matches)) {
print_r($matches);
}
Use any one parser and parse the HTML and use it. Don't use preg* functions here. Please read this answer How do you parse and process HTML/XML in PHP?

What's the error in concatenation in below code? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
What's the error in below code:
I'm getting the error as below:
PHP Parse error: syntax error, unexpected T_STRING in pdf_test_question_paper.php on line 38
$header_html = '<table border="0" width="100%" cellpadding="0" cellspacing="0" style="font-size:12px; font-family:verdana;">
<tr>
<td><img src="http://www.example.com/upload_media/coaching/logo/display/".$coaching_details['coach_inst_logo_name']." width="198"></td>
<td>
<h2 style="margin:0;padding:0;">Jumbo Exam Easing your Exam Preparation</h2>
<span>$coaching_address</span>
</td>
</tr>
<tr><td colspan="2"><hr style="background-color: #000000;height:1px;border:1px;"/></td></tr>
</table>';
Any help would be greatly appreciated.
When you wrap your string in single quotes, you're using literal values. That means $coaching_address will never be evaluated. You should use a heredoc instead for this amount of code:
$header_html = <<<EOD
<table border="0" width="100%" cellpadding="0" cellspacing="0" style="font-size:12px; font-family:verdana;">
<tr>
<td><img src="http://www.xyz.com/upload_media/coaching/logo/display/$coaching_details['coach_inst_logo_name']" width="198"></td>
<td>
<h2 style="margin:0;padding:0;">Zimma Exam Easing your Exam Preparation</h2>
<span>$coaching_address</span>
</td>
</tr>
<tr><td colspan="2"><hr style="background-color: #000000;height:1px;border:1px;"/></td></tr>
</table>
EOD;
please use the correct quotation in case of string concaternation:
$header_html = '<table border="0" width="100%" cellpadding="0" cellspacing="0" style="font-size:12px; font-family:verdana;">
<tr>
<td><img src="http://www.example.com/upload_media/coaching/logo/display/'.$coaching_details['coach_inst_logo_name'].' width="198"></td>
<td>
<h2 style="margin:0;padding:0;">Jumbo Easing your Exam Preparation</h2>
<span>'.$coaching_address.'</span>
</td>
</tr>
<tr><td colspan="2"><hr style="background-color: #000000;height:1px;border:1px;"/></td></tr>
</table>';
You start your string using single quotes, however you are trying to break out of the quotes using a double quote.
The correct code is:
$header_html = '<table border="0" width="100%" cellpadding="0" cellspacing="0" style="font-size:12px; font-family:verdana;">
<tr>
<td><img src="http://www.example.com/upload_media/coaching/logo/display/'.$coaching_details['coach_inst_logo_name'].' width="198"></td>
<td>
<h2 style="margin:0;padding:0;">Jumbo Easing your Exam Preparation</h2>
<span>'.$coaching_address.'</span>
</td>
</tr>
<tr><td colspan="2"><hr style="background-color: #000000;height:1px;border:1px;"/></td></tr>
</table>';

Categories