-1

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


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

not sending email not sending emailnot sending emailnot sending emailnot sending emailnot sending emailnot sending email?????

2 Answers2

-1

You have to use smtp settings to be able to send the mail as most hosting providers now have closing the php mail function due to security reasons, this is the script for a proper smtp mail function and dont use third party tools like php mailer just ask your hosting provider to activate mail function in pear packages

<?php
require_once "Mail.php"; 
$from = "Web Master <webmaster@example.com>"; 
$to = "Nobody <nobody@example.com>";
$subject = "Test email using PHP SMTP\r\n\r\n";
$body = "This is a test email message";
$host = "SMTPhostname"; 
$username = "webmaster@example.com"; 
$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

As mentioned - your code is at risk of sql injection so it would be wise to use a prepared statement as below.

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='vkcvkc8@gmail.com';
            $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>" );
}
Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46