hi I am just wondering how I can test the mail( ) fucntion on my local host without any email program. Is it possible?

Basically here is the code that I used(firefox shows the error message: Firefox doesn't know how to open this address because the protocol (c) isn't associated with any program:

<html>
<head>
<title>Bob's Auto Parts - Customer Feedback</title>
</head>
<body>

<h1>Customer Feedback</h1>

<p>Please tell us what you think.</p>

<form method=post action="c:/Program Files/Apache Software Foundation/Apache2.2/htdocs/processfeedback.php">
Your name: <br />
<input type=text name="name" size=40><br />
Your email address: <br />
<input type=text name="email" size=40><br />
Your feedback:<br />
<textarea name="feedback" rows=5 cols=30>
</textarea><br />
<input type=submit value="Send feedback">
</form>
</body>


and this is hte code to process this comment:

<?php
//create short variable names
$name=$_POST;
$email=$_POST;
$feedback=$_POST;

$toaddress = '';
$subject = 'Feedback from web site';
$mailcontent = 'Customer name: '.$name."\n"
.'Customer email: '.$email."\n"
."Customer comments: \n".$feedback."\n";
$fromaddress = 'From: ';

mail($toaddress, $subject, $mailcontent, $fromaddress);
?>
<html>
<head>
<title>Bob's Auto Parts - Feedback Submitted</title>
</head>
<body>
<h1>Feedback submitted</h1>
<p>Your feedback has been sent.</p>


</body>
</html>

any help would be appreciated

Dani AI

Generated

The immediate Firefox error comes from the form action in your HTML pointing at a local filesystem path (the "c:" URL). Browsers expect an HTTP(S) URL or a relative path served by Apache, not a disk path. Put both pages in Apache's htdocs (or your site folder) and use a relative action like processfeedback.php, then open the page at http://localhost/.... That will also let Apache run the PHP instead of the browser trying to open a file directly.

About sending mail: is wrong that localhost testing is impossible. PHP’s mail() does not itself deliver mail — on Windows it hands messages off to an SMTP server configured in php.ini. To test locally you have three practical options: run a local SMTP server (for full delivery, see hMailServer), or run a “mail catcher” that captures outgoing SMTP so you can inspect messages without delivering them (try smtp4dev or MailHog), or bypass mail() and send via authenticated SMTP with a library such as PHPMailer.

Fix the form-handling and validate inputs before sending. For example, read named POST fields and check mail()’s return value:

$name = trim($_POST['name'] ?? '');
$email = filter_var($_POST['email'] ?? '', FILTER_SANITIZE_EMAIL);
$feedback = trim($_POST['feedback'] ?? '');

if (mail($to, $subject, $message, $headers)) {
    echo 'Mail sent';
} else {
    echo 'Mail failed — check local SMTP/catcher and php.ini settings';
}

Troubleshooting checklist: run phpinfo() to confirm which php.ini is used and the SMTP settings; enable PHP error reporting; check the SMTP/catcher logs; verify firewall isn’t blocking port 25/587; and don’t forget to sanitize user input. See the official PHP docs on mail() for details: PHP manual.

Recommended Answers

All 6 Replies

You cannot send email from your localhost, you will need a testing server who supports mail function like, , they will offer you 400mb space without any charges you can test your mail function there. you Just need to create an account on that site.

I don't have any link with , just told you for the sake of help :)

I don't have any link with , just told you for the sake of help :)

thanks for the reply!

do you know any other way i could test it?

I think that's the only way.

I think that's the only way.

what is the reason behind that?

Don't Know exactly, you can google it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.