Title: PHP Help: mailing list subscription
Last modified: August 19, 2016

---

# PHP Help: mailing list subscription

 *  [faerystrangeme](https://wordpress.org/support/users/faerystrangeme/)
 * (@faerystrangeme)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/php-help-mailing-list-subscription/)
 * So, I would like to add a form to my website where people can enter their email
   address and they get automatically added to our mailing list. Our mailing list
   just requires an email sent to mailinglist-join@wherever to subscribe to. The
   code I have is from a friend, who has it up and working on their site. The way
   it works is there’s the form that goes in the page content, and bit of javascript
   in the header that links to a .php file. I think my problem may be that WordPress
   requires full address paths…so I tried putting the php file into the functions.
   php file so I could just call the function instead of figuring out the whole 
   address path, but I don’t think I did it right. I guess I have to do more than
   copy and paste.
 * Anyways, I would really appreciate some help on why I can’t get the subscription
   thing to work.
 * ———- HEADER ———-
    ‘<script type=”text/javascript”>
 * function GetXmlHttpObject()
    { var xmlHttp=null; try { // Firefox, Opera 8.0+,
   Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try {
   xmlHttp=new ActiveXObject(“Msxml2.XMLHTTP”); } catch (e) { xmlHttp=new ActiveXObject(“
   Microsoft.XMLHTTP”); } } return xmlHttp; } function stateChanged() { if (xmlHttp.
   readyState==4) { document.getElementById(“subscribed”).innerHTML = xmlHttp.responseText;}}
   function joinSp(str) { xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert (“
   Your browser does not support AJAX!”); return; } var url=”joinSPBA.php”; url 
   = url + “?q=” + str; xmlHttp.onreadystatechange=stateChanged; xmlHttp.open(“GET”,
   url,true); xmlHttp.send(null); } </script>’
 * ———- SEPARATE PHP FILE: joinSPBA.php ———-
    ‘<?php
 * function is_valid_address($field) {
    return (ereg(‘^[a-zA-Z0-9_.-]+@[a-zA-Z0-
   9_.-]+$’, $field)); }
 *  $q=$_GET[“q”];
    if (is_valid_address($q)) { $to = “prebusiness-join@lists.stanford.
   edu “; $subject = “(no subject)”; $message = “none”; $from = “$q”; $headers =“
   From: $from”; mail($to,$subject,$message,$headers); echo “Subscription request
   was sent!”; } else { echo “Sorry, that email address is invalid.”; } ?>’
 * ———- BODY/CONTENT ———-
    ‘<div class=”sidebar”><b>Join us!</b> Enter your email
   address below and click Subscribe to join our mailing list.
 * <p><input type=”text” id=”emailaddress” />
    <input type=”button” value=”Subscribe”
   onClick=”document.getElementById(‘subscribed’).innerHTML = ‘Sending request…’;
   joinSPBA(document.getElementById(’emailaddress’).value)” /></p> <p id=”subscribed”
   ></p>’

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [faerystrangeme](https://wordpress.org/support/users/faerystrangeme/)
 * (@faerystrangeme)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/php-help-mailing-list-subscription/#post-1226802)
 * Maybe someone will post now that it’s no longer a ridiculous hour of the morning(
   for North/South America, anyways.)
 *  Thread Starter [faerystrangeme](https://wordpress.org/support/users/faerystrangeme/)
 * (@faerystrangeme)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/php-help-mailing-list-subscription/#post-1226852)
 * Anyone?

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘PHP Help: mailing list subscription’ is closed to new replies.

 * 2 replies
 * 1 participant
 * Last reply from: [faerystrangeme](https://wordpress.org/support/users/faerystrangeme/)
 * Last activity: [16 years, 7 months ago](https://wordpress.org/support/topic/php-help-mailing-list-subscription/#post-1226852)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
