full_name ); $body = '
'; $body .= '

' . esc_html__( 'New Booking Request', 'ab-veh-take' ) . '

'; $body .= '

' . sprintf( esc_html__( 'A new %s journey request has been submitted.', 'ab-veh-take' ), $booking->journey_type === 'multistop' ? esc_html__( 'multi-stop', 'ab-veh-take' ) : esc_html__( 'one-way', 'ab-veh-take' ) ) . '

'; $body .= ''; $body .= self::row( __( 'Name', 'ab-veh-take' ), $booking->full_name ); $body .= self::row( __( 'Email', 'ab-veh-take' ), $booking->email ); $body .= self::row( __( 'Phone', 'ab-veh-take' ), $booking->phone ); $body .= self::row( __( 'Journey Type', 'ab-veh-take' ), ucfirst( $booking->journey_type ) ); if ( 'multistop' === $booking->journey_type ) { $stops = json_decode( $booking->stops, true ); $stop_lines = array(); if ( is_array( $stops ) ) { foreach ( $stops as $i => $stop ) { $label = sanitize_text_field( $stop['address'] ?? '' ); $wait_mins = ! empty( $stop['wait'] ) ? intval( $stop['wait'] ) : 0; $wait = $wait_mins > 0 ? sprintf( __( ' (%s %d %s)', 'ab-veh-take' ), __( 'wait', 'ab-veh-take' ), $wait_mins, __( 'mins', 'ab-veh-take' ) ) : ''; $stop_lines[] = ( $i + 1 ) . '. ' . $label . $wait; } } $body .= self::row( __( 'Route', 'ab-veh-take' ), implode( '
', $stop_lines ) ); } else { $body .= self::row( __( 'Pickup', 'ab-veh-take' ), $booking->pickup_address ); $body .= self::row( __( 'Destination', 'ab-veh-take' ), $booking->destination_address ); } $body .= self::row( __( 'Date', 'ab-veh-take' ), $booking->booking_date ); $body .= self::row( __( 'Time', 'ab-veh-take' ), $booking->booking_time ); $body .= self::row( __( 'Number of People', 'ab-veh-take' ), $booking->num_passengers ); $body .= self::row( __( 'Vehicle Type', 'ab-veh-take' ), $booking->vehicle_type ); $body .= self::row( __( 'Status', 'ab-veh-take' ), ucfirst( $booking->status ) ); $body .= '
'; $body .= '

' . esc_html__( 'View this booking in the dashboard', 'ab-veh-take' ) . '

'; $body .= '
'; self::mail( $to, $subject, $body ); } public static function send_user_confirmation( $booking ) { $subject = __( 'Your journey request has been received', 'ab-veh-take' ); $body = '
'; $body .= '

' . sprintf( esc_html__( 'Thank you, %s!', 'ab-veh-take' ), esc_html( $booking->full_name ) ) . '

'; $body .= '

' . esc_html__( 'We\'ve received your journey request and it is currently pending review. Our team will confirm your booking shortly.', 'ab-veh-take' ) . '

'; $body .= ''; if ( 'multistop' === $booking->journey_type ) { $stops = json_decode( $booking->stops, true ); $stop_lines = array(); if ( is_array( $stops ) ) { foreach ( $stops as $i => $stop ) { $label = sanitize_text_field( $stop['address'] ?? '' ); $wait_mins = ! empty( $stop['wait'] ) ? intval( $stop['wait'] ) : 0; $wait = $wait_mins > 0 ? sprintf( __( ' (%s %d %s)', 'ab-veh-take' ), __( 'wait', 'ab-veh-take' ), $wait_mins, __( 'mins', 'ab-veh-take' ) ) : ''; $stop_lines[] = ( $i + 1 ) . '. ' . $label . $wait; } } $body .= self::row( __( 'Route', 'ab-veh-take' ), implode( '
', $stop_lines ) ); } else { $body .= self::row( __( 'Pickup', 'ab-veh-take' ), $booking->pickup_address ); $body .= self::row( __( 'Destination', 'ab-veh-take' ), $booking->destination_address ); } $body .= self::row( __( 'Date', 'ab-veh-take' ), $booking->booking_date ); $body .= self::row( __( 'Time', 'ab-veh-take' ), $booking->booking_time ); $body .= self::row( __( 'Number of People', 'ab-veh-take' ), $booking->num_passengers ); $body .= self::row( __( 'Vehicle Type', 'ab-veh-take' ), $booking->vehicle_type ); $body .= '
'; $body .= '

' . esc_html__( 'If any of these details are incorrect, simply reply to this email.', 'ab-veh-take' ) . '

'; $body .= '
'; self::mail( $booking->email, $subject, $body ); } private static function row( $label, $value ) { $value = $value ? $value : esc_html__( '—', 'ab-veh-take' ); return '' . esc_html( $label ) . '' . wp_kses_post( $value ) . ''; } private static function mail( $to, $subject, $html_body ) { $headers = array( 'Content-Type: text/html; charset=UTF-8', self::from_header(), ); add_filter( 'wp_mail_content_type', array( __CLASS__, 'set_html_content_type' ) ); $sent = wp_mail( $to, $subject, $html_body, $headers ); remove_filter( 'wp_mail_content_type', array( __CLASS__, 'set_html_content_type' ) ); return $sent; } private static function from_header() { $site_domain = wp_parse_url( home_url(), PHP_URL_HOST ); if ( ! empty( $site_domain ) && ! in_array( $site_domain, array( 'localhost', '127.0.0.1' ), true ) && false !== strpos( $site_domain, '.' ) ) { $clean_domain = preg_replace( '/^www\./', '', $site_domain ); $from_email = 'noreply@' . $clean_domain; } else { $from_email = get_option( 'admin_email' ); } $from_name = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); $from_email = apply_filters( 'ab_veh_take_mail_from_email', $from_email ); $from_name = apply_filters( 'ab_veh_take_mail_from_name', $from_name ); return sprintf( 'From: %s <%s>', $from_name, $from_email ); } public static function set_html_content_type() { return 'text/html'; } public static function send_test_email() { $to = AB_Veh_Take_Settings::get_notification_email(); $site = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); $subject = sprintf( __( '[%s] AB Veh Take — Test Email', 'ab-veh-take' ), $site ); $body = '
' . '

' . esc_html__( 'Test Email', 'ab-veh-take' ) . '

' . '

' . sprintf( esc_html__( 'This is a test email from AB Veh Take, confirming that notifications sent to %s are being delivered correctly.', 'ab-veh-take' ), '' . esc_html( $to ) . '' ) . '

' . '

' . esc_html__( 'If you received this, your Admin Notification Email is working.', 'ab-veh-take' ) . '

' . '
'; $sent = self::mail( $to, $subject, $body ); return array( 'sent' => (bool) $sent, 'to' => $to, ); } }