0 レビュー
2 回答
php-HTMLコンテンツを含むcURL
URLに投稿する必要があり、curlを使用してこれを行っています。しかし、問題は私が投稿しているHTMLコンテンツにあります。 HTMLメールの送信をリクエストしているこのページを使用しています。したがって、インラインスタイルになります。 urlencode()またはrawurlenocde()を実行すると、これらのスタイル属性が削除されます。そのため、メールは正しく表示されません。これを回避してHTMLをそのまま投稿するにはどうすればよいですか?
これは私のコードです:
$mail_url = "to=".$email->uEmail;
$mail_url .= "&[email protected]";
$mail_url .= "&subject=".$email_campaign[0]->email_subject;
$mail_url .= "&type=signleOffer";
$mail_url .= "&html=".rawurlencode($email_campaign[0]->email_content);
//open curl request to send the mail
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count(5));
curl_setopt($ch,CURLOPT_POSTFIELDS,$mail_url);
//execute post
$result = curl_exec($ch);
わからない
0
レビュー
答え :
解決策:
例を次に示します。http_build_query()を使用して、値の配列から投稿データを作成します。
<?php
//Receiver debug
if($_SERVER['REQUEST_METHOD']=='POST'){
file_put_contents('test.POST.values.txt',print_r($_POST,true));
/*
Array
(
[to] => [email protected]
[from] => [email protected]
[subject] => subject
[type] => signleOffer
[html] =>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Mail Template</title>
<style>.yada{color:green;}</style>
</head>
<body>
<p style="color:red">Red</p>
<p class="yada">Green</p>
</body>
</html>
)
*/
die;
}
$curl_to_post_parameters = array(
'to'=>'[email protected]',
'from'=>'[email protected]',
'subject'=>'subject',
'type'=>'signleOffer',
'html'=>'
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Mail Template</title>
<style>.yada{color:green;}</style>
</head>
<body>
<p style="color:red">Red</p>
<p class="yada">Green</p>
</body>
</html>
'
);
$curl_options = array(
CURLOPT_URL => "http://localhost/test.php",
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query( $curl_to_post_parameters ), //<<<
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false
);
$curl = curl_init();
curl_setopt_array($curl, $curl_options);
$result = curl_exec($curl);
curl_close($curl);
?>
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。