John Davidson

email - PHP Sending Mail with XAMPP

0 comments
Message:


I've been searching for hours to find the answer to my email sending problem in PHP...


No posts on stackoverflow or google helped me so far, thats why im trying it now here.


I am using XAMPP and i want to send an email to my web.de mail with my custom domain mail


My PHP Class (E-Mails are correct in my private file):


sending.php


<?php

$to = "MY OWN EMAIL";
$subject = "Thank you for downloading";

$headers = array(
"MIME-Version" => "1.0",
"Content-Type" => "text/html;charset=UTF-8",
"From" => "EMAIL CREATED ON STRATO",
"Reply-To" => "EMAIL CREATED ON STRATO"
);

$message = "Test :)";

$send = mail($to, $subject, $message, $headers);

echo ($send ? "Mail was sent" : "error :(");
?>

http://localhost/mailtest/sending.php Output: error :(


sendmail.ini


[sendmail]

smtp_server=smtp.strato.de
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=EMAIL CREATED ON STRATO
auth_password=EMAIL PASSWORD CREATED ON STRATO
force_sender=EMAIL CREATED ON STRATO

php.ini


...

[mail function]
SMTP=smtp.strato.de
smtp_port=587
sendmail_from = EMAIL CREATED ON STRATO
sendmail_path = "\"Z:\XAMPP\sendmail\sendmail.exe\" -t"

...


line 18: echo error_get_last()['message'];

Output: Trying to access array offset on value of type null in Z:\XAMPP\htdocs\mailtest\sending.php on line 18

Thanks for helping!



My Answer:

$to = "recipient@example.com";
$subject = "Test Email";
$message = "This is a test email from PHP";
$headers = "From: sender@example.com";

if (mail($to, $subject, $message, $headers)) {
echo "Email sent successfully";
} else {
echo "Email sending failed";
}

?>


Make sure to replace "recipient@example.com" and "sender@example.com" with your actual email addresses. Also, make sure that your XAMPP server is properly configured to send emails. You may need to check your XAMPP settings or consult with your hosting provider for further assistance.

Rate this post

3 of 5 based on 2397 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us