Menu

From using both name & email address?

Help
Mercer
2007-08-21
2013-06-03
  • Mercer

    Mercer - 2007-08-21

    I've got my form working properly, but now I'm wondering if I can make it show a display name as well as address based on the user input?

    For example, I want the email to come in as from "John Smith <john.smith@hismail.com>", like any normal email.

    I have figured out how to get the email address to show up in the From field, but am still struggling with the name. Is there a way to do this, or am I out of luck on this one?

    Here is my process.php for reference:

    <?php
    include("global.inc.php");
    $errors=0;
    $error="The following errors occured while processing your form input.<ul>"; 
    pt_register('POST','Name'); 
    pt_register('POST','Email'); 
    pt_register('POST','Subject'); 
    pt_register('POST','Department'); 
    pt_register('POST','Comments'); 
    $Comments=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $Comments);
    if($Name=="" || $Email=="" || $Subject=="" || $Department=="" || $Comments=="" ){ $errors=1; 
    $error.="<li>You did not enter one or more of the required fields. Please go back and try again."; }
    if($errors==1) echo $error;
    else{
    $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
    $message="Name: ".$Name."
    Email: ".$Email."
    Subject: ".$Subject."
    Department: ".$Department."
    Comments: ".$Comments."
    ";
    $message = stripslashes($message);

    if($Department=="WebsiteComment") {
    // First case email according to first department selection
    mail("a@a.com","$Subject",$message,"From: $Email");
    } else if($Department=="GroupForumComment") {
    // Second case email according to second department selection
    mail("b@b.com","$Subject",$message,"From: $Email");
    } else {
    // Third case is the default in case of any mixup in the department selection
    mail("a@a.com","$Subject",$message,"From: $Email");
    }

    header("Refresh: 0;url=thanks.html");
    ?><?php
    }
    ?>

     
    • TNTEverett

      TNTEverett - 2007-08-22

      mail("a@a.com","$Subject",$message,"From: $Name <$Email>");

       
      • eschamp

        eschamp - 2007-08-22

        I have this in process.php and it doesn't work:

        $from="From: ".$Email."\r\n";

        $message = stripslashes($message);
        mail("actual_group_name@yahoogroups.com","SUBSCRIBE",$message,$from);

        For some reason, Yahoogroups thinks the message is coming from the host on which the form resides!

         
        • TNTEverett

          TNTEverett - 2007-08-23

          You are not following any formal syntax for email headers so don't bother with anything more than just the email address.
          $from=$Email; or just put $Email in the last mail() function field.
          mail("actual_group_name@yahoogroups.com","SUBSCRIBE",$message,$Email);

          Yahoo is right.  The email has no choice but to reveal it is coming from the web host where the form resides.  When you use the mail() function the web server where the form resides has an email server related to the same site.  You can control the from address but not the email server that sends the mail. 

           
          • eschamp

            eschamp - 2007-08-23

            Are you saying thst even if I use $Email as you suggest above, Yahoo will not see the email as coming from the value of %Email?

             
            • TNTEverett

              TNTEverett - 2007-08-23

              This is the header showing the source of an email from one of my forms.  As you can see the Email variable (Email@mydomain.com) from my form is visible but the server domain and my web site main account name (mywebaccountemail@gamma.newwebsite.com) is the real source of the email being sent. 

              From: webaccountemail@gamma.newwebsite.com; on behalf of; Email@mydomain.com

              This may or may not be typical but I have never been concerned with it since none of my customers have any complaints. 

               
              • eschamp

                eschamp - 2007-08-23

                Is that a "yes" or a "no"? :-)

                I'm trying to set up a form that people can use to subscribe to a yahoogroups mailing list.

                To subscribe to such a mailing list, one sends an email to groupname-subscribe@yahoogroups.com, from the email address account they want on the list.

                In my form, I have them enter that email address as the value of $Email.

                How do I satisfy Yahoogroups? Thanks.

                 
                • TNTEverett

                  TNTEverett - 2007-08-23

                  Neither :)
                  This may or may not be happening on your form.  It will depend on how your web host has the mail function setup.  First contact your host and tell them what you are doind and ask if there is some email feature/server that you can use that will not modify the header you define (the To and From address is transmitted unmodified).  You will also need to speak with Yahoo to see if there are specific constraints that will prevent you from sending an email in the format you expect to send. 

                  Why would you not just present a link to your customers that uses there own email account to send this email? 
                  For instance:
                  mailto:yahoogroupemail@yahoo.com?subject=subscription

                  This type of link causes the users email application to pop up with a new message.  The To: field is prepopulated with "yahoogroupemail@yahoo.com", the Subject: is prepopulated with "subscription", all the user needs to do is click "Send".  It is possible to prepopulate any field to prepare the users message so they do nothing but click "Send" after clicking your link. 

                   
                  • eschamp

                    eschamp - 2007-08-24

                    The mailto: thing is interesting. What is not clear is who the message will appear to be coming from. I.e., yahoogroups wants the subscribe message to come from the address that is to be subscribed and the mailto approach does not give any control over that.

                    Thanks.

                     
                    • TNTEverett

                      TNTEverett - 2007-08-24

                      The mailto approach sends the email from the user's own email account on the PC used to browse to your web page.  If you have a PC with an email application, this email application is used to send the email via the mailto method.  The account used is dependant on the default email account setup in the email application.  It's as simple as that.

                       
                      • eschamp

                        eschamp - 2007-08-24

                        Suppose there is no email application per se on the PC (the user has not configured Outlook or OE and is using his ISP's webmail site).

                        What happens then?

                         
                        • TNTEverett

                          TNTEverett - 2007-08-24

                          It doesn't work, but how many people have an internet account without email?  For those wanting to remain anonymous by having and using a free web email account which they can easily get by submitting fraudulent signup credentials, maybe you don't want those people as customers anyway. 
                          I suggested the mailto option because it was a simple solution to your seemingly simple problem.  If your problem is more complex obviously you've got to pursue the more complex solution I first suggested. 
                          Recap:
                          Find out if your web host will allow you to manipulate the email header in order to satisfy Yahoo's requirements, or contact Yahoo and see if there is any other method that will work given your limitations. 

                           
      • Mercer

        Mercer - 2007-08-23

        Exactly what I needed. I knew it was something simple that I just wasn't seeing. Thanks again for your help!

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.