Jump to content

IF you are a PHP genious you should read this:


ambaker

Recommended Posts

I have this code in dreamweaver for a php mailer. I should warn you I am print designer not a web designer so this world is so new to me. I am just learning! In my mailer when you push send from my website, I never get an email!? I have no idea what I can do. Any help out there? Here is the code I am using:

 

<?php

 

$subject = $_REQUEST["subject"];

$message = $_REQUEST["message"];

$sender = $_REQUEST["sender"];

 

 

$full_message = $_SERVER['REMOTE_ADDR'] . "\n\n" . $message;

$message= $full_message;

 

$message = stripslashes($message);

$subject = stripslashes($subject);

$sender = stripslashes($sender);

 

$subject = "Invitation Inquiry ". $subject;

 

if(isset($message) and isset($subject) and isset($sender)){

mail("amie@amb-design.com", $subject, $message, "From: $sender");

}

?>

Link to comment
Share on other sites

My first question would be if you KNOW that the mail() function is being executed. If it is you may have issues with your settings which could range from your mail server to your SMTP ports, etc.

 

I usually use a mailer class for all of my email needs as they do the hard work for me :)

 

http://phpmailer.codeworxtech.com/ is a pretty good one too!

Link to comment
Share on other sites

I wish I knew what you are talking about. I downloaded my site off of flashden. The code was written for me. I am not sure if i messed something up on accident or if it is just my settings like you mentioned. Which tutorial in that site do you suggest I use?

Link to comment
Share on other sites

Mailer classes are nice since they are predefined for you... and easier to utilize. But if the mail you are sending is a pretty simple one, a class is an overkill, given that class has other facilities involved.

 

Also, please tell us what was the trouble you have been encountering, a more detailed one. :)

Trace your code first to find where you messed up. Then tell us, so we can help.

 

PS

 

am not a PHP genius... am also a greenhorn (less than a year of experience) but I think being in here makes me more challenged since I can read some troubles other people have, learn new things and sharing of ideas. :)

Link to comment
Share on other sites

I should clarify... I am not trying to send email, I am trying to receive it. My site: www.amb-design.com,

if you go to the contact page and type me an email... click send it tells you it sent it, but i NEVER receive it!!!!

 

 

...tear.

Link to comment
Share on other sites

So it's basically a contact form? A user enters a subject, message etc. and the server sends it to an email.

 

But you don't get the email?

 

Like someone suggested do you KNOW that it's trying to mail()? Try adding

 

echo "Message sent!";

 

below mail().

 

So effectively:

 

if(isset($message) and isset($subject) and isset($sender)){
   mail("amie@amb-design.com", $subject, $message, "From: $sender");
   echo "Message sent!";
}

 

If it outputs Message Sent when you submit the form and you dont get the email then it's a problem on the server's end.

 

If it DOESN'T output Message sent then something is wrong and your 3 variables are not set (and thus the if is false)

Link to comment
Share on other sites

The code above allows you to send and not to receive mail. The problem can be caused by several reasons:

 

If you are the one who made the mail sending:

  1. the mail() might have never been called.

  2. there was an error in sending.

  3. the server you have is not configured to send mail.

etc.

 

If you are trying to receive it (via PHP):

  1. The above code is not the right one, instead use IMAP functions, PHP has it.

  2. The mail server you have does not allow you to retrieve such mails from PHP,

      other than the one they are providing.

Link to comment
Share on other sites

I placed the added code line as suggested, no luck. Yes, a contact form is what it is called. I am learning as I go so my apologies to all who are rolling their eyes at me.

 

I still don't get an email. I have my mail forwarded to hotmail... could this be part of the problem that hotmail isn't capable of receiving this?

 

I am looking into the other suggestions you guys provided but I am looking up as I go because I don't really know what it means.

Link to comment
Share on other sites

Well here's a script I made a while back. Just tested it and it works fine.

 

<?
if ($submitting == "yes") {
$message = wordwrap($message, 70);
$recipent = "someone@domain.com";
$subject = "" . $subject . "";
$name = "" . $name . "";
$sender = "" . $sender . "";
$headers = 'From: ' . $name . '' . "\r\n" .
    'Reply-To: ' . $sender . '' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
mail($recipent,$subject,$message,$headers);
echo "Email sent";
exit;
}
?>
<form name="emailbomb" method="post" action="<?=$PHP_SELF?>">
<p>Your Name:</p><br>
<input name="name" type="text" class="field_text" id="name" maxlength="25"><br><br>
<p>Your email:</p><br>
<input name="sender" type="text" class="field_text" id="sender" maxlength="25"><br><br>
<p>Subject: </p><br>
<input name="subject" type="text" class="field_text" id="subject" size="16" maxlength="25"><br><br>
Message: <textarea rows=15 cols=60 name="message" id="message"></textarea><br>
<input type="hidden" name="submitting" value="yes" />
<input type="submit" name="submit" value="Send" />
</form>

 

make sure you edit $recipent on line 4 with the email that should be receiving all this.

Link to comment
Share on other sites

This is not the correct way to check whether mail() is returning a true value.

 

I would use:

 

if(isset($message) and isset($subject) and isset($sender)){

  $res = mail("amie@amb-design.com", $subject, $message, "From: $sender");

 

  if ($res) {

  echo "Message sent!";

  }

  else

  {

  echo "Message not sent!";

  }

}

else {

echo "The message could not be sent because the message, subject or sender values were not set";

}

 

If you get the error message 'Message not sent!' then your next move is to check whether the smtp server is configured on your server or not.

Link to comment
Share on other sites

If I read your code correctly, if someone put that their email address is "bob@gmail.com" then in your inbox, it would say "From: bob@gmail.com" ?

 

 

If I am correct in that interpretation, then there's your problem right there. Many(maybe all?) shared hosting servers won't allow email to be sent on behalf of another domain other than itself. It just won't email. UInfortunately, it probably won't return false, as it did try to email, it just failed(because of the server not allowing it to).

 

 

Solution: change the $sender variable to anything@YOURdomain.com. You can, however, specify a reply-to variable, which alows you to reply back to their email, at the domain they provided. But first get your code to email, then worry about a reply-to.

 

Also, don't stripslashes... you never added them(that is, unless magic_quotes is enabled)

Link to comment
Share on other sites

You're right, SMTP servers don't allow messages to be sent from a different domain however when you try to do this it returns a 503: Bad Recipient error which causes mail to fail.

 

I would recommend trying to run the mail command on it's own and see if any errors are returned:

 

  $res = mail("amie@amb-design.com", "Test Message", "This is just a test message", "From: $sender");

 

  if ($res) {

  echo "Message sent!";

  }

  else

  {

  echo "Message not sent!";

  }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.