www.webdeveloper.com
Results 1 to 15 of 15

Thread: Send Email on localhost

  1. #1
    Join Date
    Nov 2008
    Location
    Wiltshire, England
    Posts
    108

    Send Email on localhost

    I'm trying to setup being able to use the mail() function on localhost as using free hosting all the time is a pain when the ftp connection keeps dropping and it takes hours to do just a simple bit of code.

    I've done some searching and apparently it's possible to do this by changing the php.ini file to use the smtp connection of the ISP. My ISP is Virgin Media so I tried to use smtp.virginmedia.com which I found from their website but it seems unable to connect to this. I also read that it was possible to use your own email account and as I have a hotmail.com account I tried to use the live smtp however it gives an error that basically translates to needing a secure connection.

    If anyone has managed to do this I would appreciate some help to get this working. Thanks

  2. #2
    Join Date
    Nov 2008
    Location
    Wiltshire, England
    Posts
    108
    Just as an update: I've tried to use something called Argosoft Mail Server .NET which I understand is quite a popular mail server to use however I keep getting this error: SMTP server response: 510 User not local. We don't relay in *file name*.

    I looked this problem up and people keep mentioning a tickbox that isn't there anymore called authentication not required if local or something like that.

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,616
    If I need to use SMTP, I normally use the PHPMailer class, which comes with its own SMTP class. Here's one of their sample code pages showing an example of using SMTP: http://phpmailer.worxware.com/index.php?pg=examplebsmtp
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Nov 2008
    Location
    Wiltshire, England
    Posts
    108
    Thanks for your reply I would certainly give this a try. I'd just like to use something that I can use the mail function on without having to upload the website to a free host. I've also been looking at the mail package in PEAR but I'll try this first

  5. #5
    Join Date
    Nov 2008
    Location
    Wiltshire, England
    Posts
    108
    Either a brand new version has just come out of the examples haven't been updated as none of them seem to work. I've had a look elsewhere however but I keep getting this error:

    Notice: Undefined variable: from in C:\wamp\www\phpmailer\phpmailer.inc.php on line 259

    However in my code I am specifying a From value. Here is the source code for a simple test file:

    Code:
    <?php
    	require_once("phpmailer.inc.php");
    	
    	$mail = new PHPMailer();
    	
    	$mail->IsSMTP();
    	$mail->Host = "smtp.live.com";
    	
    	$mail->From = "sr_tennant@hotmail.com";
    	$mail->AddAddress("sr_tennant@hotmail.com");
    	
    	$mail->Subject = "Test";
    	$mail->Body = "Test Body Message";
    	
    	if (!$mail->Send())
    	{
    		echo "Message was not sent";
    	}
    	else
    	{
    		echo "Message successfully sent";
    	}
    ?>

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,616
    From the example, it looks like you should be using the SetFrom() method:
    PHP Code:
    $mail->SetFrom("sr_tennant@hotmail.com"); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  7. #7
    Join Date
    Nov 2008
    Location
    Wiltshire, England
    Posts
    108
    That method no longer exists however I think I've fixed it but I had to edit the phpmailer code. Instead of the $header->$from code I've changed it to $this->From. It doesn't show an error anymore at least.

    Still I can't send an email. I've been trying to use my hotmail account to send an email but it still won't work and I've tried all kinds of tutorials etc for making phpmailer work with PHP but they all seem to be outdated. Perhaps I should just download a mail server and try that instead?

  8. #8
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,616
    Are you sure you got the PHP 5 version? I ask because it looks like the download link on their site goes to the PHP 4 version at sourceforge. Try this page: http://sourceforge.net/projects/phpm...Mailer%20v5.1/ to get PHPMailer 5.1, or if you want 5.0 (which is the last one I downloaded and has worked fine for me), go to http://sourceforge.net/projects/phpm...us%20Versions/.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  9. #9
    Join Date
    Nov 2008
    Location
    Wiltshire, England
    Posts
    108
    Ah thank you you're right I must have been using an old version even though I clicked for PHP 5. Thank you for the link perhaps this will help solve some of the confusion

  10. #10
    Join Date
    Nov 2008
    Location
    Wiltshire, England
    Posts
    108
    Finally managed to get it working and an email was successfully sent. Thanks for your help

  11. #11
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,616
    Sweet. I used their contact form to tell them about the bad links. I hope their email script worked.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  12. #12
    Join Date
    Nov 2008
    Location
    Wiltshire, England
    Posts
    108
    Haha that would be controversial if it didn't .

    Just while we're on the subject of sending email in PHP instead of making a new thread do most emails sent from free hosting end up in Hotmail's junk folder? It's just that while I am intending to use email on localhost for the time being I've been writing scripts on a free account from 000 web host. The only thing is if I don't include any headers the email goes straight into inbox as "Nobody" but as soon as I start including header information it will always get sent to the junk folder and flagged as "suspicious"

  13. #13
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,616
    Spam filters are an arcane mystery which I have not studied much. Your message could be filtered based on email headers (or lack thereof), suspicious content in the body or subject, and the IP address of the sending host (and maybe forwarding hosts in between?). So if you are on a shared host that is noted for hosting accounts that spam, that in and of itself might be a problem.

    But like I said, it's not something I'm any sort of expert on, and there is lots of information (and probably misinformation) out there on the web to sift through.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  14. #14
    Join Date
    Nov 2008
    Location
    Wiltshire, England
    Posts
    108
    I'm guessing it's some sort of error in my headers due to the fact that when I take the headers out the email will always land in the inbox which seems a bit strange to me.

    The headers just contain the usual MIME-Version, Content-type , charset and From and I've checked them over and they are all correct in fact I think I copied them from somewhere else as they are pretty much all the same except for the From which is just my email address.

  15. #15
    Join Date
    May 2011
    Posts
    1
    I registered an account just to tell you guys that you are awesome for solving this problem for me! By the way, phpmailer's website still has not corrected their download link for the php 5 version of phpmailer. Evidently their contact form either doesn't work or they don't check their messages.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles