PHP to SQL and email form submission -
i have working php form taking data form in backend of website , inserting sql database applicable. issue is, whenever try , set send data email address ( email captured in form & email defined ) recieve error 500.
code below:
<?php /* attempt mysql server connection. assuming running mysql server default setting (user 'root' no password) */ $link = mysqli_connect("#", "#", "#", "#"); // check connection if($link === false){ die("error: not connect. " . mysqli_connect_error()); } // escape user inputs security $name = mysqli_real_escape_string($link, $_post['name']); $initials = mysqli_real_escape_string($link, $_post['initials']); $item = mysqli_real_escape_string($link, $_post['item']); $issue = mysqli_real_escape_string($link, $_post['issue']); $tel = mysqli_real_escape_string($link, $_post['tel']); $email = mysqli_real_escape_string($link, $_post['email']); $cost = mysqli_real_escape_string($link, $_post['cost']); $loggedby = mysqli_real_escape_string($link, $_post['loggedby']); $bag = mysqli_real_escape_string($link, $_post['bag']); $charger = mysqli_real_escape_string($link, $_post['charger']); // attempt insert query execution $sql = "insert `repairs` (`name`,`initials`,`item`, `issue`, `telephone`,`email`, `cost`, `loggedby`, `bag`, `charger`) values ('$name', '$initials', '$item', '$issue', '$tel', '$email', '$cost', '$loggedby', '$bag', '$charger')"; if(mysqli_query($link, $sql)){ header('location:repairs.php'); } else{ echo "error: not execute $sql. " . mysqli_error($link); } $to = "emailaddress@emails.co.uk,$email" $subject= "thankyou $name - repair has been logged" $body= "<h2>thankyou $name</h2> /n confirmation email regarding $item /n repair log below: /n $item /n $issue /n/n <h3>accessories</h3> /n bag - $bag /n charger - $charger /n/n repair logged $loggedby on echo date("d-m-y"); /n/n contact on $tel & $email when $item ready collect. /n/n loud crowd - 01302 965482 /n repairs@loudcrowdit.co.uk /n www.loudcrowd.agency /n" $mail ($to,$subject,$body); // close connection mysqli_close($link); ?>
does know why receive error?
internal server error means there's error in server side script, in case :
$to = "emailaddress@emails.co.uk,$email" // missing semicolon
the missing semicolon above triggers unexpected '$subject' (t_variable)
also here :
$subject= "thankyou $name - repair has been logged"
this code should use :
<?php /* attempt mysql server connection. assuming running mysql server default setting (user 'root' no password) */ $link = mysqli_connect("#", "#", "#", "#"); // check connection if ($link === false) { die("error: not connect. " . mysqli_connect_error()); } // escape user inputs security $name = $_post['name']; $initials = $_post['initials']; $item = $_post['item']; $issue = $_post['issue']; $tel = $_post['tel']; $email = $_post['email']; $cost = $_post['cost']; $loggedby = $_post['loggedby']; $bag = $_post['bag']; $charger = $_post['charger']; // attempt insert query execution $sql = "insert `repairs` (`name`,`initials`,`item`, `issue`, `telephone`,`email`, `cost`, `loggedby`, `bag`, `charger`) values (?,?,?,?,?,?,?,?,?,?)"; $stmt = mysqli_prepare($link, $sql); mysqli_stmt_bind_param($stmt, 'ssssssssss', $name, $initials, $item, $issue, $tel, $email, $cost, $loggedby, $bag, $charger); if (mysqli_stmt_execute($stmt)) { $to = "emailaddress@emails.co.uk,$email"; $subject = "thankyou $name - repair has been logged"; $body = "<h2>thankyou $name</h2> /n confirmation email regarding $item /n repair log below: /n $item /n $issue /n/n <h3>accessories</h3> /n bag - $bag /n charger - $charger /n/n repair logged $loggedby on " . date("d-m-y") . "/n/n contact on $tel & $email when $item ready collect. /n/n loud crowd - 01302 965482 /n repairs@loudcrowdit.co.uk /n www.loudcrowd.agency /n"; if (mail($to, $subject, $body)) { header('location:repairs.php'); } } else { printf("error: %s.\n", mysqli_stmt_error($stmt)); } mysqli_close($stmt); // close connection mysqli_close($link); ?>
Comments
Post a Comment