2016-08-04 1 views
-1

私は、テーブルに "tb"というテーブルを持つデータベース "db"を持っています。データベースへのイメージ(テーブルtb)。私のウェブサイトからイメージパスを取得し、リンクとして電子メールで送信します

次のように私はPHPでメールのためのスクリプトを作成しました:

$recipients="[email protected]"; 

$subject="some subject"; 

$headers= "'From: <[email protected]>'"; 

$message="<a href='http://http://example.com/image/imagename.jpg' target='_blank'>Click here to see image</a>"; 

mail($recipients,$subject,$message,$headers); 
} 

メール機能は、優れた作業が、受信者がメールを受け取ったときに、メールの本文内のリンクは、以下のように示されている:

<a href='http://http://mcqpage.com/image/imagename.jpg' target='_blank'>Click here to see image</a> 

受信者が「画像を見るにはここをクリック」リンクをクリックし、対象のファイルをクリックした後にのみ受信します。

+0

HTMLメールを送信する必要があります。http://stackoverflow.com/questions/11238953/send-html-in-email-via-php –

答えて

0

あなたが他の人によって提案されたメールのヘッダーにメールタイプを設定する必要があります。

$headers= "'From: <[email protected]>'\r\n"; 
$headers .= "Content-Type: text/html; charset=UTF-8\r\n"; 
0

あなたはheadersにメッセージの種類を指定する必要があります。

$to = '[email protected]'; 
$from = '[email protected]'; 

$subject = 'Website Change Request'; 

$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n"; 
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n"; 
$headers .= "CC: [email protected]\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"; 
// This line is the most important! 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

$message = '<html><body>'; 
$message .= '<h1>Hello, World!</h1>'; 
$message .= '</body></html>'; 

mail($to, $from, $message, $headers); 
1

PHPでメールを送信すると、プレーンテキストの電子メールを送信するか、HTMLの電子メールを送信するかを設定できます。デフォルトはプレーンテキストで、電子メールコンテンツは解析されません。そのため、リンクをHTMLリンクの代わりに通常のテキストとして表示します。

HTMLコンテンツの電子メールを送信するには、コンテンツタイプヘッダーを設定する必要があります。したがって、ヘッダーは次のようになります。

$headers= "'From: <[email protected]>'" . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

また、必要に応じて文字セットを変更することもできます。

関連する問題