Tony Stark Tony Stark - 1 year ago 129
PHP Question

How to add email servern & port into this PHP

I have a PHP code at my server in which if data is added to the database, it sends a mail to the admin. Recently I bought a webhosting and uploaded my files. Problem is my mails from the server were getting delayed so I asked the webhosting. They said me to add this "" and port 25 in my PHP to receive the mail fast. I don't have much knowledge of PHP. Can you help me where to insert this in the code below:


// get data
$name = $_POST['name'];
$alamat = $_POST['alamat'];
$kota = $_POST['kota'];
$provinsi = $_POST['provinsi'];
$name2 = $_POST['name2'];
$date_n_time = $_POST['date_n_time'];
$phone = $_POST['phone'];
$order_list = $_POST['order_list'];
$comment = $_POST['comment'];
$emails = $_POST['email'];

$sql_query = "set names 'utf8'";
$stmt = $connect->stmt_init();
if($stmt->prepare($sql_query)) {
// Execute query
// store result

// insert data into reservation table
$sql_query = "INSERT INTO tbl_reservation(Name, Alamat, Kota, Provinsi, Number_of_people, Date_n_Time, Phone_number, Order_list, Comment, Email)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

$stmt = $connect->stmt_init();
if($stmt->prepare($sql_query)) {
// Bind your variables to replace the ?s
// Execute query
$result = $stmt->affected_rows;
// store result
//$result = $stmt->store_result();

// get admin email from user table
$sql_query = "SELECT Email
FROM tbl_user";

$stmt = $connect->stmt_init();
if($stmt->prepare($sql_query)) {
// Execute query
// store result

// if new reservation has been successfully added to reservation table
// send notification to admin via email
$to = $emails;
$subject = $reservation_subject_2;
$message .= "Dear " .$provinsi."\r\n";
$message .= $reservation_message_2."\r\n\n";
$message .= "Pick Drop :" .$name2."\r\n";

$from = $admin_email;
$headers = "From:" . $from."\r\n".
echo "OK";
echo "Failed";

Answer Source

Your code is using PHP's built in mail() command to send the message - you can see that line almost at the end of your code:


The server and port that mail() uses are configured in PHP's configuration file, php.ini. You may be able to override those settings by adding this to your code - anywhere above the mail() line.

ini_set('SMTP', '');
ini_set('smtp_port', 25);

If you want to use that server/port always, from other PHP code, you'll either need to make the same change in the other files that send mail, or update the main php.ini configuration file.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download