free hosting service - Need PHP Mail help

au001com

New Member
Messages
1
Reaction score
0
Points
1
Hi, I am fairly new to php. any way i have added a feedback form and when ever i try to send a test feedback to my email i don't actually receive any thing.
I test this using xampp and it works fine.

i was informed it's to do with using smtp or something.

My php code is as listed. Please note email address has been removed.


<?php
$name = $_POST['name'];
$priority = $_POST['priority'];
$message = $_POST['message'];
$formcontent=" From: $name \n Priority: $priority \n Message: $message";
$recipient = "placeholder@placeholder.com";
$subject = "Feedback";
$mailheader = "From: \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo " Thank you for your feedback" . " -" . "<a href='contact.html' style='text-decoration:none;color:green;'>Return</a>";
?>

any help would be good.

thanks
 

caftpx10

Well-Known Member
Messages
1,534
Reaction score
114
Points
63
I see that there is a mistake in your code.

$formcontent=" From: $name \n Priority: $priority \n

The code mark in red is incorrect.
The one below should do for that part:

$formcontent = " From: " . $name . "\n Priority: " . $priority . "\n";
You may want to apply the way I did it into your code.

This code is also vulnerable to email injection, refer to this to test and fix this vulnerability: http://www.phpsecure.info/v2/article/MailHeadersInject.en.php

I would in fact suggest looking into the links below the article to try to fill in as much holes as possible.

Using 'or die()' is a bad way of error handling, why?:
http://at-byte.com/technology/why-using-or-die-php-bad-practice
What to use instead?:
http://www.phpfreaks.com/blog/or-die-must-die

Also, X10 could've disabled the mail function since there is already a email service thingy on CPanel which you should use.
But please be aware that sending too much emails in a short time can get your account suspended so I would really do something about spamming.
 
Last edited:

Skizzerz

Contributors
Staff member
Contributors
Messages
2,928
Reaction score
118
Points
63
mail() is enabled and can be used. Note that you must use \r\n when separating email headers, simple \n is not sufficient (you are doing this, but just making it clear). Those two PHP snippets posted above perform the same task (@caftpx10: look up string interpolation in PHP, you can actually embed $variables in double-quoted strings and it works just fine). You are also missing the "To:" header, although that shouldn't impact the successful sending of email.

I checked our email system and it successfully sent all of your feedback emails, so the issue is somewhere on your end -- check your spam folder to see if it landed up there, and if not it is possible that your email provider is blocking emails from x10.
 
Top