I'm going to be as detailed as i can,
My code now works with sending an Email to the recipient with a random generated 'ticketId' and a link to a webpage..
But my problem is:
I'd like to be able to send multiple generated ticketId's to the recipient. (that has already been inserted into the Database)
include_once 'includes/dbh.inc.php';
//random ticketid generator
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
//amount is the amount of tickets the customer purchases
$amount = $_POST['amount'];
$email = $_POST['email'];
$days = $_POST['day'];
$x = 1;
do{
$lol = generateRandomString();
$sql = "INSERT INTO tickets (ticketId, email, accomodation, days, nights) VALUES ( '$lol' , '$email', NULL, '$days', NULL)";
mysqli_query($conn, $sql);
$x++;
} while ($x <= $amount);
if(isset($_POST['submit'])){
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPmailer;
$mail->Host="smtp.gmail.com";
$mail->Port=2525;
$mail->SMTPAuth=true;
$mail->SMTPSecure='tls';
$mail->Usernam='random@gmail.com';
$mail->Password='xxxxxxxxxxxxx';
$mail->setFrom($email);
$mail->addAddress('random@gmail.com');
$mail->addReplyTo($email);
$mail->isHTML(true);
$mail->Subject='Your Fyrelyt tickets are waiting for you';
$mail->Body='<h1> xxx </h1> <p> ticket id: </p>' .$lol;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
}
Aucun commentaire:
Enregistrer un commentaire