2017-07-16 43 views
-1

電子メールを送信するemailnot送信emailnot送信emailnot送信emailnot送信emailnot送信しない電子メール を送信しない電子メール

$sql = "insert into book (uid,interest,tid,lid)values('$id','$interest','$tid','$lid') "; 
 
$result = $conn->query($sql); 
 
if($result) 
 
{ 
 
\t echo"<script type='text/javascript'> 
 
\t alert('added'); 
 
\t </script>"; 
 
\t 
 
$message = "Your have interest in ".$interest.""; 
 
$to=$email; 
 
$subject="Booked for ".$title.""; 
 
$from = '[email protected]'; 
 
$body="Booked for ".$title."located in".$location.".You will be charged with".$cost. 
 
\t \t ".Contact:".$contact.""; 
 
$headers = "From:".$from; 
 
mail($to,$subject,$body,$headers); 
 

 

 
} 
 
else 
 
\t { 
 
\t echo"<script type='text/javascript'> 
 
\t alert('error'); 
 
\t </script>"; 
 
} 
 
\t

経由で詳細を送信することはできません?????

+0

アラートの1件が表示されていますか?どれ? –

+0

あなたのコードはSQLインジェクションの危険性があります – RamRaider

答えて

-1

ほとんどのホスティングプロバイダがセキュリティ上の理由からphpメール機能を終了しているので、これは適切なsmtpメール機能用のスクリプトであり、サードパーティ製のツールを使用しないので、メールを送信するにはsmtp設定を使用する必要があります以下のようにprepared statementを使用するのが賢明だろうので、あなたのコードは、SQLインジェクションの危険にさらされている - PHPのメーラーは、ちょうど述べたようにPEARパッケージ

<?php 
require_once "Mail.php"; 
$from = "Web Master <[email protected]>"; 
$to = "Nobody <[email protected]>"; 
$subject = "Test email using PHP SMTP\r\n\r\n"; 
$body = "This is a test email message"; 
$host = "SMTPhostname"; 
$username = "[email protected]"; 
$password = "yourPassword"; 
$headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); 
$smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); 
if (PEAR::isError($mail)) { 
echo("<p>" . $mail->getMessage() . "</p>"); } 
else 
{ echo("<p>Message successfully sent!</p>"); 
} 
?> 
-1

にメール機能を有効にするにはホスティングプロバイダにお問い合わせください。

try{ 
    $sql='insert into book (uid, interest, tid, lid) values (?,?,?,?)'; 
    $stmt=$conn->prepare($sql); 

    if($stmt){ 
     /* 
      assuming parameters are 
      ----------------------- 
      uid=integer 
      interest=string 
      tid=integer 
      lid=integer 
     */ 
     $stmt->bind_param('isii', $id, $interest, $tid, $lid); 
     $result=$stmt->execute(); 

     if($result && $stmt->affected_rows==1){ 

      $message = "You have interest in {$interest}"; 
      $to=$email; 
      $from='[email protected]'; 
      $subject="Booked for {$title}"; 
      $body="{$message}\n\nBooked for {$title} located in {$location}.\n\nYou will be charged with {$cost}\n\nContact:{$contact}"; 
      $headers=array(); 
      $headers[]="MIME-Version: 1.0"; 
      $headers[]="Content-type: text/plain; charset:utf-8"; 
      $headers[]="To: {$to}"; 
      $headers[]="From: {$from}"; 
      $headers[]="Reply-To: {$from}"; 
      $headers[]="X-Mailer: PHP/".phpversion(); 

      $status = mail($to, $subject, $body, implode("\r\n", $headers)); 
      throw new Exception($status ? 'success - mail sent' : 'fail - mail not sent'); 
     } else { 
      throw new Exception('Failed to insert data'); 
     } 
    } else { 
     throw new Exception('Unable to prepare sql query'); 
    } 
}catch(Exception $e){ 
    exit("<script>alert('{$e->getMessage()}');</script>"); 
} 
関連する問題