Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

send() failing without errors on shared hosting

Go to End

9 Posts   2830 Views


Community Member, 26 Posts

10 March 2010 at 5:39am

I'm failing to understand why my Silverstripe installation on shared hosting refuses to send emails, either from a custom function like this...

class ContactPage extends Page
	static $db = array(
		'Mailto' => 'Varchar(100)', //Email address to send submissions to
		'SubmitText' => 'HTMLText' //Text presented after submitting message
	//CMS fields
	function getCMSFields() {
		$fields = parent::getCMSFields();
		$fields->addFieldToTab("Root.Content.OnSubmission", new TextField('Mailto', 'Email submissions to'));	
		$fields->addFieldToTab("Root.Content.OnSubmission", new HTMLEditorField('SubmitText', 'Text on Submission'));	
		return $fields;	

class ContactPage_Controller extends Page_Controller
	function ContactForm() {
      	// Create fields
	$Params = Director::urlParams();
	    $fields = new FieldSet(
		    new TextField('Name', 'Name*'),
			new EmailField('Email', 'Email*'),
			new TextareaField('Comments','Comments*')
	    // Create action
	    $actions = new FieldSet(
	    	new FormAction('SendContactForm', 'Send')
		// Create action
		$validator = new RequiredFields('Name', 'Email', 'Comments');

	    return new Form($this, 'ContactForm', $fields, $actions, $validator);
	function SendContactForm($data) {
	 	//Set data
		$From = $data['Email'];
		$To = $this->Mailto;
		$Subject = "Website Contact message";  	  
		$email = new Email($From, $To, $Subject);
		//set template
		//populate template
		//send mail
	  	//return to submitted message
		Director::redirect(Director::baseURL(). $this->URLSegment . "/?success=1");

	public function Success()
		return isset($_REQUEST['success']) && $_REQUEST['success'] == "1";

...or from a page created with the UserDefinedForm module. There are no errors logged and no errors displayed on the page--everything seems to check out, except that somewhere between the page and Email.php, the mail function just doesn't seem to work. I'm running PHP Version 5.2.13, with a configuration that works just fine when I write, outside of Silverstripe...
$email = $_POST['email'] ;
$message = $_POST['message'] ;
mail( "[email protected]", "Email Subject", $message, "From: $email" );
print "Email sent";

2+ years ago, someone recommended installing phpmailer to work around Silverstripe's native mail functioning. Is this STILL the best way to send emails from Silverstripe on a shared host???


Community Member, 26 Posts

10 March 2010 at 8:42am

In case anyone else is having the same problem, here's relevant code that's a little closer(?) to the problem:

	if(!($result = @mail($to, $subject, $fullBody, $headers, "-f$bounceAddress"))) {
		$result = mail($to, $subject, $fullBody, $headers);

Sample message (raw) with variable names noted for clarity

[email protected]         //$to
Sample Subject         //$subject
This is a multi-part message in MIME format.         //$fullBody

Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

I just really wanted to email you and say hi.

Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
=09<base href=3D"" />

<p class=3D"body">
=09I just really wanted to email you and say hi.



MIME-Version: 1.0         //$headers
Content-Type: multipart/alternative; boundary="----=_NextPart_159628161319"
Content-Transfer-Encoding: 7bit
From: [email protected]
X-Mailer: SilverStripe Mailer - version 2006.06.21 (Sent from "")
X-Priority: 3
X-SilverStripeSite: mysite

Ideas? Anyone?


Community Member, 26 Posts

11 March 2010 at 11:21am

After much futzing around in the guts of Mailer.php and Email.php, I decided to change the recipient of my contact page emails to an address on my host, so that instead my script would try to send emails to [email protected] instead of [email protected]. Emails which were subsequently attempted were generated and received, but I have no idea why.
Can anyone illuminate me?


Community Member, 323 Posts

12 March 2010 at 2:17am

Hi! I cannot enlighten you, since I had the same problem several months ago. I didn’t remembered what I did then, so I didn’t replied to your post. Now I remember! I’m going to check the wiki and try to write a line about this somewhere.

Best regards,


Community Member, 26 Posts

12 March 2010 at 3:38am

That's great. Could you let me know?


Community Member, 323 Posts

12 March 2010 at 4:14am

There’s nothing more to know: I seem to remember that as soon as I changed the address to one of the same domain, all started to work. I’m really sorry, but I can’t recall nothing else. I’ve checked my custom code for UserDefinedForm and the lines related to send() are not modified.


Community Member, 26 Posts

12 March 2010 at 4:29am

Understood. Thanks.


Forum Moderator, 4102 Posts

12 March 2010 at 4:38am

You need to talk to your hosting provider. This happens all the time if your mail is hosted on a different server. The mailer looks at the destination domain and says, "oh, that's me.. I don't need to do anything".. so I never goes out to the internet to send the mail.

There's a setting somewhere in Apache that they can tweak to force the mailer to always look outside of its own DNS to send mail...

Go to Top